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.netTRUE/FALSE14139616484f62d_c_stamp1382425648
.lampbrother.netTRUE/FALSE13508896474f62d_lastvisitdeleted
.lampbrother.netTRUE/FALSE14139616484f62d_lastposother
.lampbrother.netTRUE/FALSE13508896474f62d_cideleted
.lampbrother.netTRUE/FALSE14139616484f62d_ck_info%2F%09.lampbrother.net
.lampbrother.netTRUE/FALSE13508896474f62d_regactivatedeleted
分享到:
------解決方案--------------------
要全路徑!
$temp = realpath(tempnam('./tep', 'cookie'));