PHP头条
热点:

phpcurl重定向有关问题


php curl 重定向问题
刚接触curl想用curl post信息,并且重定向到目的页面(带着发送的POST信息重定向)

$url = "http://localhost/opms/WebContent/test_output.php";
$post_data = array (
    "foo" => "bar",
    "query" => "Nettuts",
    "action" => "Submit"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_MAXREDIRS,10);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$output = curl_exec($ch);
curl_close($ch);


照着网上的东西设置了很多也不知道有没有用,只不过想让最后地址栏的地址变为test_output.php,但总不成功。
是不是curl根本就不能跳转?还是我设置问题,求各位大大解答,谢谢!
------解决方案--------------------
CURLOPT_FOLLOWLOCATION 的意思是:
当目标页出现跳转,即 http 头中有 Location 指令时,跟着读取新的目标页
如果没有设置该属性,则 curl 只会读取一页

www.phpzy.comtrue/phprm/18211.htmlTechArticlephpcurl重定向有关问题 php curl 重定向问题 刚接触curl想用curlpost信息,并且重定向到目的页面(带着发送的POST信息重定向) $url="http://localhost/opms/WebContent/test_output.php"; $post_data=array( "foo...

相关文章

PHP之友评论

今天推荐