php专区

 首页 > php专区 > PHP高级 > 缓存异常处理 > curl模拟登陆有关问题

curl模拟登陆有关问题

分享到:
【字体:
导读:
         摘要:curl模拟登陆问题本帖最后由 zkg510168343 于 2013-10-22 15:29:21 编辑 <?php $url="http://bbs.lampbrother.net/login.php"; $ur...

curl模拟登陆有关问题
curl模拟登陆问题
本帖最后由 zkg510168343 于 2013-10-22 15:29:21 编辑
$url = "http://bbs.lampbrother.net/login.php";
$urls = "http://bbs.lampbrother.net";
$lgt = 0;
$user = "zkg12345";
$pass = "123456";
$question = 0;
$hideid = 1;

$temp = tempnam('./tep', 'cookie');

$postdata = "forward=&jumpurl=".$urls."&step=2&lgt=".$lgt."&pwuser=".$user."&pwpwd=".$pass."&question=".$question."&answer=&hideid=".$hideid."&cktime=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_COOKIEJAR, $temp);


$data = curl_exec($ch);
curl_close($ch);

//echo $data;          //这里打印的时候可以看到已经登陆成功正在跳转
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://bbs.lampbrother.net/index.php');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $temp);

curl_exec($ch);
curl_close($ch);
?>

登陆的完成后,我打印的时候发现是登陆成功了的,显示正在跳转页面,可是再次请求首页还是未登录状态,别的页面也是没有登陆,请问这是什么问题,怎样调试

在cookie临时文件里 生成了一个 coo810B.tmp文件
值为
# Netscape HTTP Cookie File
# http://curlm.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

.lampbrother.net TRUE / FALSE 1413961648 4f62d_c_stamp 1382425648
.lampbrother.net TRUE / FALSE 1350889647 4f62d_lastvisit deleted
.lampbrother.net TRUE / FALSE 1413961648 4f62d_lastpos other
.lampbrother.net TRUE / FALSE 1350889647 4f62d_ci deleted
.lampbrother.net TRUE / FALSE 1413961648 4f62d_ck_info %2F%09.lampbrother.net
.lampbrother.net TRUE / FALSE 1350889647 4f62d_regactivate deleted

------解决方案--------------------
要全路径!
$temp = realpath(tempnam('./tep', 'cookie')); curl模拟登陆有关问题
分享到:
如何强制jpg,js,css等连接资源,如果不...
如何强制jpg,js,css等连接资源,如果不存在就直接404而不重写 怎么强制jpg,js,css等连接资源,如果不存在就直接404而不重写我在本机架设了个网站 http://www.laji.com 网站文件夹下有2个文件, .htaccess文件:Options +FollowSymLinks -MultiViews RewriteEngine on RewriteBase / # All other pages # Don&#...
PHP中查找文件的相对路径也许绝对路径的...
PHP中查找文件的相对路径也许绝对路径的工具 PHP中查找文件的相对路径或者绝对路径的工具以前面试题目中有一题为求两个文件的相对路径,当时觉得没有电脑,书写代码太麻烦,没有做那个题目,今日工作比较闲遐,就想起这事来,完成了两个函数,代码未经过实际生产环境考验,如引用至生产环境,还请慎重阅读,主要是参考学习...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……