Heim  >  Artikel  >  Backend-Entwicklung  >  curl模拟登陆问题

curl模拟登陆问题

WBOY
WBOYOriginal
2016-06-23 14:24:55829Durchsuche

本帖最后由 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'));

要全路径!
$temp = realpath(tempnam('./tep', 'cookie'));
问题解决了,我想请教一下

我只是修改了这里 $cookie_file    =    tempnam('./temp','cookie');
就可以了,cookie的文件存放位置必须要在 temp 文件夹下吗?我之前是自己创建的文件夹tem就不行

算了结了吧,也没人,谢谢了  xuzuning 版主

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn