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

WBOY
Release: 2016-06-02 11:32:15
Original
1430 people have browsed it

跳转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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template