我正在使用php / curl自动登录网站。
虽然我的cookie没有得到所有必要的变量。
我曾经 FireFox的HTTPFox 来观看帖子,我错过了JSESSIONID
键/值。
HTTPFox Cookie的屏幕截图
虽然设置了其他变量。我注意到JSESSIONID
有一个不同的 PATH 。我想我错过了一些额外的curl参数?或者可能是第二次拨打其他网址?
myCookie.txt
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
mydomain.com FALSE / FALSE 0 RDMZ_ROUTEID R4276449038
mydomain.com TRUE / FALSE 0 amlbcookie 13
mydomain.com TRUE / FALSE 0 txdmvtokenext somereallylongkey
mydomain.com FALSE / FALSE 0 SERVERID 13
有人对我做错了什么有所了解吗?
CURL代码
// log in
$loginURL = "http://www.somedomain.com/login";
$username = "myUsername";
$password = "myPassword";
$gotoURL = "http://www.somedomain.com/somepage";
$postfields = 'IDToken1='.$username.'&IDToken2='.$password.'&IDButton=Log In&goto='.$gotoURL ;
$cookie_jar = "myCookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginURL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/x-www-form-urlencoded',
'Connection: Keep-Alive'
));
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
$page = curl_exec($ch);
echo $page;
echo "Error: ".curl_error($ch);
curl_close($ch);