嗨,我在POST请求中尝试PHP Post Request,认为它可能对我有用,我的代码如下所示
$sub_req_url = "http://localhost/index1.php";
$ch = curl_init($sub_req_url);
$encoded = '';
// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
foreach($_POST as $name => $value) {
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
形成index.php文件和index2.php是同一目录中的另一个文件,当我打开页面时,我的error.log文件中出现以下错误
[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal …Run Code Online (Sandbox Code Playgroud)