Heim  >  Artikel  >  Backend-Entwicklung  >  php模拟登录目标网站,为何302没有跟随跳转.cookie已经获得.求解惑.

php模拟登录目标网站,为何302没有跟随跳转.cookie已经获得.求解惑.

WBOY
WBOYOriginal
2016-06-02 11:32:151398Durchsuche

跳转phpcurlcookie

<code> <?phperror_reporting (0);$user       = 'cckk263';//邮箱密码$pass       = '54131421';//登陆$url = 'https://www.mql5.com/zh/auth_login/';//创建一个用于存放cookie信息的文件$cookie= dirname(__FILE__).'/tmp/cookie.txt';$fields_post = array('Login'=> $user,'Password'=> $pass,'RedirectAfterLoginUrl'=>'https://www.mql5.com/zh','RememberMe'=>false,);//step 1//获取一个cookie$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);$content1 = curl_exec($ch);curl_close($ch);//step 2//post 数据;$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);// 从证书中检查SSL加密算法是否存在curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);// 自动跟随跳转curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_AUTOREFERER, 1);curl_setopt($ch, CURLOPT_POST, count($fields));curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields_post));$result= curl_exec($ch);curl_close($ch);</code>
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