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

WBOY
发布: 2016-06-02 11:32:15
原创
1430 人浏览过

跳转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>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板