php - 在vBulletin中使用curl登录网站

标签 php curl authentication vbulletin

我一直在尝试登录网站(www.siamchart/forum)按照此链接上的说明进行操作.. Login to remote site with PHP cURL 。我无法通过登录。运行以下脚本后,它将我重定向到相同的登录页面(www.siamchart/forum),但没有成功登录。

我的代码如下..

$username="ABC"; 
$password="12345"; 
$url="www.siamchart.com/forum/login.php?do=login"; 
$cookie="siamchart_cookie.txt"; 

$postdata = "vb_login_username=".$username."&vb_login_password=".$password; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result;  
curl_close($ch);

编辑

论坛正在使用 vBulletin。这是登录页面中的脚本

<script type="text/javascript" src="clientscript/vbulletin_md5.js?v=4111"></script>
   <form id="navbar_loginform" action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
   <fieldset id="logindetails" class="logindetails">
   <div>
     <div>
     <input type="text" class="textbox default-value" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="User Name" />
     <input type="password" class="textbox" tabindex="102" name="vb_login_password" id="navbar_password" size="10" />
     <input type="text" class="textbox default-value" tabindex="102" name="vb_login_password_hint" id="navbar_password_hint" size="10" value="Password" style="display:none;" />
     <input type="submit" class="loginbutton" tabindex="104" value="Log in" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" />
     </div>
   </div>
   </fieldset>
   .
   .
</script>

我做错了什么吗?非常感谢。

最佳答案

该网站正在重定向您,但您已禁用重定向。更改为:

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
                                          ^--

关于php - 在vBulletin中使用curl登录网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14078426/

相关文章:

php - 从 mysql 查询返回额外的项目

php - PEAR 和 Composer 有什么区别?

php - 在下拉选择中,如何从数据库中填写完整的表单字段

php - 扩展 cURL 最大 URL 长度或其他选项?

PHP 登录屏幕

authentication - 应用客户端身份验证(登录)和 CQRS

php - 如何在成功处理 PHP 脚本时打开模态框?

linux - 如何将 tail -f 输出重定向到 curl(HTTP 流)

php - 网站是否可能无法登录?

http - 指示 "not logged in"的正确 HTTP 代码是什么?