-
- $cookie_jar = dirname(__file__)."/pic.cookie";
-
复制代码
二、获取cookie
将cookie存入文件
-
-
$url = "http://1.2.3.4/";
- $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_jar);
- $content = curl_exec($ch);
- curl_close($ch);
复制代码
三、模拟浏览器获取验证码
该服务器验证码有漏洞,可以自己指定。
取出cookie,一起提交给服务器,让服务器以为是浏览器打开登陆页面。
-
-
$ch = curl_init();
- curl_setopt($ch, curlopt_url, 'http://1.2.3.4/getcheckpic.action?rand=6836.185874812305');
- curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
- curl_setopt($ch, curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer, 1);
- $ret = curl_exec($ch); // bbs.it-home.org
- curl_close($ch);
复制代码
四、post提交
-
-
$post = "name=2&usertype=1&passwd=asdf&logintype=1&rand=6836&imagefield.x=25&imagefield.y=7";
- $ch = curl_init();
- curl_setopt($ch, curlopt_url, "http://1.2.3.4/loginstudent.action");
- curl_setopt($ch, curlopt_header, false);
- curl_setopt($ch, curlopt_returntransfer,1);
- curl_setopt($ch, curlopt_postfields, $post);
- curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
- $result=curl_exec($ch);
- curl_close($ch);
复制代码
五、到指定页面获取数据
-
-
$ch = curl_init();
- curl_setopt($ch, curlopt_url, "http://1.2.3.4/accountcarduser.action");
- curl_setopt($ch, curlopt_header, false);
- curl_setopt($ch, curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer,0);
- curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
- $html=curl_exec($ch);
- // var_dump($html);
- curl_close($ch);
复制代码
以上介绍了php curl通过获取cookie实现模拟登录的方法,php模拟登录的几个例子,希望对大家有所帮助。
>>> 更多 php模拟登录 文章,专题链接:php模拟登录 php curl模拟登录教程大全
|