您好,欢迎访问一九零五行业门户网

普通的表单登陆怎么修改成php curl模拟表单登陆

用户名:
密码:

2.php
header('content-type:text/html;charset=utf-8');if ($_post['loginname'] == 'lee' && $_post['loginpass'] == '123456') { header('location:http://bbs.csdn.net');} else { }
请教一下这样的表单怎么修改成模拟登陆 我是这样写的为什么不对呢
新建一个1.php
header('content-type:text/html;charset=utf-8'); $user = 'lee'; //登陆用户名 $pass = '123456'; //登陆密码 $post_fields = loginname={$user}&loginpass={$pass};$ch = curl_init(); curl_setopt($ch,curlopt_url,'http://localhost/2.php');curl_setopt($ch,curlopt_post,1);curl_setopt($ch,curlopt_postfields,$post_fields);curl_setopt($ch, curlopt_returntransfer, 1); curl_exec($ch);curl_close($ch);
回复讨论(解决方案) echo curl_exec($ch);
另外你的2.php是跳转了,并没有返回内容。
改成echo file_get_contnets('location:http://bbs.csdn.net'); 试试
header('location:http://bbs.csdn.net');
形成的 http 头
http/1.1 302 found
date: wed, 26 feb 2014 09:16:38 gmt
location: http://bbs.csdn.net
content-length: 0
content-type: text/html;charset=utf-8
你不跟着跳转吗?
curl_setopt($ch, curlopt_followlocation, true);
header('location:http://bbs.csdn.net');
形成的 http 头
http/1.1 302 found
date: wed, 26 feb 2014 09:16:38 gmt
location: http://bbs.csdn.net
content-length: 0
content-type: text/html;charset=utf-8
你不跟着跳转吗?
curl_setopt($ch, curlopt_followlocation, true);
谢谢斑竹的帮忙 我改成了这样
1.php
header('content-type:text/html;charset=utf-8'); $user = 'lee'; //登陆用户名 $pass = '123456'; //登陆密码 $post_fields = loginname={$user}&loginpass={$pass};$ch = curl_init(); curl_setopt($ch,curlopt_url,'http://localhost/2.php');curl_setopt($ch,curlopt_post,1);curl_setopt($ch,curlopt_postfields,$post_fields);curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_followlocation,true);curl_exec($ch);curl_close($ch);
2.php
header('content-type:text/html;charset=utf-8');if ($_post['loginname'] == 'lee' && $_post['loginpass'] == '123456') { header('location:http://bbs.csdn.net');} else { }
执行1.php 还是空白 并没有实现跳转
#1 不是说了吗?
echo curl_exec($ch);
你不输出结果怎么能行?
nbsp;html public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd>
csdn论坛首页 - csdn.net
谢谢大家的帮忙
其它类似信息

推荐信息