Curl Joomla-通过脚本登录来宾用户
更新: 我发现了一个可能导致问题的IIS错误。请看这篇文章 _________________原始问题_______________________________________________________________________________ 我有一个Guest Joomla用户,他可以访问我网站中一个不太私密但仍然私密的部分。我希望一些用户,通过包含散列的特殊链接访问,能够在有限访问权限的来宾帐户下自动登录 为了实现这一点,我正在关注布伦特·弗里亚的一篇文章 这一过程的一部分正在发挥作用Curl Joomla-通过脚本登录来宾用户,curl,joomla1.5,Curl,Joomla1.5,更新: 我发现了一个可能导致问题的IIS错误。请看这篇文章 _________________原始问题_______________________________________________________________________________ 我有一个Guest Joomla用户,他可以访问我网站中一个不太私密但仍然私密的部分。我希望一些用户,通过包含散列的特殊链接访问,能够在有限访问权限的来宾帐户下自动登录 为了实现这一点,我正在关注布伦特·弗里亚的一篇文章 这一过程的一部分
- 我能够发出cURL请求,刮取令牌值
- 脚本运行后,我可以查看Joomla会话表并查看来宾用户的条目
- 当我在设置cookie之前打印cookie的值时,它与会话表中的cookie匹配
$uname = "DocGuest";
$upswd = "pass";
//This is the URL of the normal login form on the website
$url = "http://localhost/index.php?option=com_content&view=article&id=115&Itemid=283";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('./cookie.txt'));
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('./cookie.txt'));
curl_setopt($ch, CURLOPT_HEADER, TRUE );
$ret = curl_exec($ch);
if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)) {
preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof);
}
$postfields = array();
$postfields['username'] = $uname;
$postfields['passwd'] = $upswd;
$postfields['lang'] = 'en';
$postfields['option'] = 'com_user';
$postfields['task'] = 'login';
$postfields[$spoof[1]] = '1';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
// Get logged in cookie and pass it to the browser
preg_match('/^Set-Cookie: (.*?);/m', $ret, $m);
$cookie=explode('=',$m[1]);
print_r($cookie); //Cookie matches session table here?
//header("location: http://localhost/index.php?option=com_k2&view=itemlist&layout=category&task=category&id=1&Itemid=158");
setcookie($cookie[0], $cookie[1], 3600*24, '/');
哇,有趣的问题,我假设您使用的是XAMPP,因为域的原因。我看到的第一件可能导致问题的事情是在传输cookie之前发生重定向
//header("location: http://localhost/index.php?option=com_k2&view=itemlist&layout=category&task=category&id=1&Itemid=158");
setcookie($cookie[0], $cookie[1], 3600*24, '/');
应该是:
setcookie($cookie[0], $cookie[1], 3600*24, '/');
header("location: http://localhost/index.php?option=com_k2&view=itemlist&layout=category&task=category&id=1&Itemid=158");
我要做的另一件事是不设置cookie的路径。我知道在过去我遇到过XAMPP路径不能像我想象的那样工作的问题。尝试使用:
setcookie($cookie[0], $cookie[1], 3600*24);
@布伦特修士-我向你发出蝙蝠信号,布伦特修士:)谢谢你的时间-我更新了我的问题。事实上,我使用IIS7是为了适应生产环境(我知道,我宁愿使用LAMP)。至于标题/cookie顺序。我也这么认为,但事实证明Web服务器不应该关心顺序。另外,在PHP文档中的setCookie页面上——大约有10条评论,有一篇帖子提到重定向应该放在第一位。两者都试过了。。