当前位置:首页 » 编程语言 » phpcurl模拟登录

phpcurl模拟登录

发布时间: 2022-08-31 13:15:23

php CURL 实现 模拟登陆 为何目标网站没有登陆的反应呢 高手请进

1、表单登陆地址不对

2、表单名不对,名字是username 和 password 没有ls

<?php
$curl=curl_init();
$cookie_jar=tempnam('./tmp','cookie');
curl_setopt($curl,CURLOPT_URL,'http://bbs.miaozhan360.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes');//这里写上处理登录的界面
curl_setopt($curl,CURLOPT_POST,1);
$request='username=wonderwiller&password=wonderwiller';
curl_setopt($curl,CURLOPT_POSTFIELDS,$request);//传递数据
curl_setopt($curl,CURLOPT_COOKIEJAR,$cookie_jar);//把返回来的cookie信息保存在$cookie_jar文件中
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);//设定返回的数据是否自动显示
curl_setopt($curl,CURLOPT_HEADER,false);//设定是否显示头信息
curl_setopt($curl,CURLOPT_NOBODY,false);//设定是否输出页面内容
$r=curl_exec($curl);//返回结果
echo$r;

curl_close($curl);//关闭
$curl2=curl_init();
curl_setopt($curl2,CURLOPT_URL,'http://bbs.miaozhan360.com/forum.php');//登陆后要从哪个页面获取信息
curl_setopt($curl2,CURLOPT_HEADER,false);
curl_setopt($curl2,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl2,CURLOPT_COOKIEFILE,$cookie_jar);
$content=curl_exec($curl2);
echo$content;
?>

Ⅱ 如何判断php中curl模拟登陆是否成功

/**
* 模拟登录
*/

//初始化变量
$cookie_file = "tmp.cookie";
$login_url = "";
$verify_code_url = "";

echo "正在获取COOKIE...\n";
$curlj = curl_init();
$timeout = 5;
curl_setopt($curl, CURLOPT_URL, $login_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($curl,CURLOPT_COOKIEJAR,$cookie_file); //获取COOKIE并存储
$contents = curl_exec($curl);
curl_close($curl);

echo "COOKIE获取完成,正在取验证码...\n";
//取出验证码
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $verify_code_url);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$img = curl_exec($curl);
curl_close($curl);

$fp = fopen("verifyCode.jpg","w");
fwrite($fp,$img);
fclose($fp);
echo "验证码取出完成,正在休眠,20秒内请把验证码填入code.txt并保存\n";
//停止运行20秒
sleep(20);

echo "休眠完成,开始取验证码...\n";
$code = file_get_contents("code.txt");
echo "验证码成功取出:$code\n";
echo "正在准备模拟登录...\n";

$post = "username=maben&pwd=hahahaha&verifycode=$code";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
$result=curl_exec($curl);
curl_close($curl);

//这一块根据自己抓包获取到的网站上的数据来做判断
if(substr_count($result,"登录成功")){
echo "登录成功\n";
}else{
echo "登录失败\n";
exit;
}

Ⅲ 我想用PHP的curl做一个带验证码的模拟登陆,可是我不太清楚header中应包含什么

模拟浏览器登陆应用开发,最关键的地方是突破登陆验证。CURL技术不只支持http,还支持https。区别就在多了一层SSL加密传输。
如果是要登陆https网站,php记得要支持openssl。还是先拿一个例子来分析。

Ⅳ PHP的curl模拟·登录老是失败出现了405错误

405 是指请求的 URL 不支持请求的方法, htm(除伪静态)是静态页面,是只能使用 get 方法的,而你要登录,要用post,而你这里也确实是用的 post,那么我觉得你应该是 URL 取错了。像这种 post 的地址都要是有程序处理的,你再回去看看原来页面中 form 上的 action 地址吧

Ⅳ php curl 无法实现模拟登陆

<?php
$discuz_url = 'http://127.0.0.1/discuz/';//论坛地址
$login_url = $discuz_url .'logging.php?action=login';//登录页地址

$post_fields = array();
//以下两项不需要修改
$post_fields['loginfield'] = 'username';
$post_fields['loginsubmit'] = 'true';
//用户名和密码,必须填写
$post_fields['username'] = 'tianxin';
$post_fields['password'] = '111111';
//安全提问
$post_fields['questionid'] = 0;
$post_fields['answer'] = '';
//@todo验证码
$post_fields['seccodeverify'] = '';
//获取表单FORMHASH
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}

//POST数据,获取COOKIE,cookie文件放在网站的temp目录下
$cookie_file = tempnam('./temp','cookie');
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
//取到了关键的cookie文件就可以带着cookie文件去模拟发帖,fid为论坛的栏目ID
$send_url = $discuz_url."post.php?action=newthread&fid=2";

$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
//这里的hash码和登陆窗口的hash码的正则不太一样,这里的hidden多了一个id属性
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*id="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}

$post_data = array();
//帖子标题
$post_data['subject'] = 'test2';
//帖子内容
$post_data['message'] = 'test2';
$post_data['topicsubmit'] = "yes";
$post_data['extra'] = '';
//帖子标签
$post_data['tags'] = 'test';
//帖子的hash码,这个非常关键!假如缺少这个hash码,discuz会警告你来路的页面不正确
$post_data['formhash']=$formhash;

$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_REFERER, $send_url); //伪装REFERER
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$contents = curl_exec($ch);
curl_close($ch);
//清理cookie文件
unlink($cookie_file);
?>

Ⅵ php curl 模拟登陆的问题验证码怎么破

网络技术飞速发展,红黑较量也是日新月异,我们要想取得长久的胜利,就不能得过且过,想绕过一切验证码,是不可能实现的。

建议:
用curl模拟登陆页面获取验证码图片,手工录入

当然了,如果后台是你自己的就不要验证码就OK了,但这是个 个例,不是泛指,希望能帮到你。

Ⅶ php curl 模拟登录 失败不成功 高手来解救!

请使用SNOOPY,你网络一下就有下载地址了他是对CURL的封装,大网站很多都用这个

热点内容
随机启动脚本 发布:2025-07-05 16:10:30 浏览:535
微博数据库设计 发布:2025-07-05 15:30:55 浏览:32
linux485 发布:2025-07-05 14:38:28 浏览:310
php用的软件 发布:2025-07-05 14:06:22 浏览:760
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:437
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:735
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:249
java的开发流程 发布:2025-07-05 12:45:11 浏览:696
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:288
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:838