首页 > 作文

PHP如何获取Cookie并实现模拟登录

更新时间:2023-04-08 21:48:31 阅读: 评论:0

一、定义cookie存储路径

必须使用绝对路径

$cookie_jar = dirname(__file__).”/pic.cookie”;

二、获取cookie

将cookie存入文件

$url = "http://1.2.3.4/";$ch = curl_init();curl_topt($ch, curlopt_url, $url);curl_topt($ch, curlopt_header, 0);curl_topt($ch, curlopt_returntransfer, true);curl_topt($ch, curlopt_cookiejar, $cookie_jar);$content = curl_exec($ch);curl_clo($ch);

三、模拟浏览器获取验证码

该服务器验证码有漏洞,可以自己指定全国英语四六级官网

取出cookie,一起提交给服务器,让服务器以为是浏览器打开登陆页面

$ch = curl_init();curl_topt($ch, curlopt_url, 'http://1.2.3.4/getcheckpic.action?rand=6836.185874812305');curl_topt($ch, curlopt_cookiefile, $cookie_jar);cu卖盒饭rl_topt($ch, curlopt_header, 0);curl红色影片观后感_topt($ch, curlopt_returntransfer, 1);$ret = curl_exec($ch);curl_clo($ch);

四、post提交

$post = "name=2&urtype=1&冬季养生小知识amp;passwd=asdf&logintype=1&rand=6836&imagefield.x=25&a虹之间歌词mp;imagefield.y=7";  $ch = curl_init();curl_topt($ch, curlopt_url, "http://1.2.3.4/loginstudent.action");curl_topt($ch, curlopt_header, fal);curl_topt($ch, curlopt_returntransfer,1);curl_topt($ch, curlopt_postfields, $post);curl_topt($ch, curlopt_cookiefile, $cookie_jar);$result=curl_exec($ch);curl_clo($ch);

五、到指定页面获取数据

$ch = curl_init();curl_topt($ch, curlopt_url, "http://1.2.3.4/accountcardur.action");curl_topt($ch, curlopt_header, fal);curl_topt($ch, curlopt_header, 0);curl_topt($ch, curlopt_returntransfer,0);    curl_topt($ch, curlopt_cookiefile, $cookie_jar);$html=curl_exec($ch);// var_dump($html);curl_clo($ch);

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。

本文发布于:2023-04-08 21:45:41,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/d2e3f70c66832f96c0ed282afa2bc35f.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP如何获取Cookie并实现模拟登录.doc

本文 PDF 下载地址:PHP如何获取Cookie并实现模拟登录.pdf

标签:服务器   验证码   浏览器   页面
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图