Heim  >  Artikel  >  Backend-Entwicklung  >  php curl 重定向有关问题

php curl 重定向有关问题

WBOY
WBOYOriginal
2016-06-13 11:17:58850Durchsuche

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

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


照着网上的东西设置了很多也不知道有没有用,只不过想让最后地址栏的地址变为test_output.php,但总不成功。
是不是curl根本就不能跳转?还是我设置问题,求各位大大解答,谢谢!


------解决方案--------------------
CURLOPT_FOLLOWLOCATION 的意思是:
当目标页出现跳转,即 http 头中有 Location 指令时,跟着读取新的目标页
如果没有设置该属性,则 curl 只会读取一页
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn