vBulletin Curl登录重定向无法正常工作

时间:2015-01-02 04:24:46

标签: php curl cookies vbulletin

我已经多次看过非常类似的问题&已经尝试过,但我无法得到结果。

https://stackoverflow.com/questions/21369197/curl-login-vbulletin-cookie

Login to site with curl in vBulletin

...

我真的很感激能够帮助我登录论坛的人。能够查看各种帖子。

到目前为止,这就是我所做的

$username="username"; 
$password="password"; 
$url="www.example.com/login.php?do=login"; 
$cookie="cookie.txt"; 


$postdata = "".

        'do=login'.
        '&s='.
        '&securitytoken=<security token here>'.
        '&vb_login_md5password=<md5 password here>'.
        '&vb_login_md5password_utf=<same as the one above>'.
        '&vb_login_password='.
        '&vb_login_password_hint=Password'.
        '&vb_login_username=username';


$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_COOKIEFILE, $cookie);
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);

如果我设置了curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);,它会返回一个未登录的页面,尽管cookie已经登录了信息。

1 个答案:

答案 0 :(得分:1)

好的,而不是使用file_get_contents($user_url)。我使用了php_curl&amp;终于得到了登录页面。

$ch = curl_init(); 

curl_setopt ($ch, CURLOPT_URL, $user_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_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
$result = curl_exec ($ch); 

curl_close($ch);


echo $result;  // the logged in page

对于有类似问题的人可能会有帮助。