我有这个脚本:
$ch = curl_init($url_path.'admin/');
$cookiefile = $srv_path."admin/cookie.txt" ;
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec ($ch);
//
curl_setopt($ch, CURLOPT_PROXY, "http://127.0.0.1.:8888");
curl_setopt($ch, CURLOPT_PROXYPORT, 8888);
curl_setopt($ch, CURLOPT_HEADER, 1);
preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);
$xid = substr($m[1], 10);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url_path.'admin/login.php');
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xid_7d781='.$xid.'$username=*****&password=******&mode=login&usertype=P&redirect=admin');
# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL # not to print out the results of its query.
# Instead, it will return the results as a string return value # from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
//
//echo('EXECUTE 1st REQUEST (FORM LOGIN)');
$page = curl_exec ($ch);
curl_close ($ch);
echo $page;
但是当我调用它时,表单字段是空白的。此外,返回的方法是GET而不是POST。为什么要返回GET?
相同的代码,如果我尝试正确运行另一个域,这也很奇怪。有可能post方法被某些东西阻止了吗?
我试图用var_dump回应任何可能的错误(curl_error($ ch));但是字符串是空的。