2

I been trying to login to a site (www.siamchart/forum) by following instruction on this link.. Login to remote site with PHP cURL. I cannot past through the login. After running the following script, it redirect me to the same login page (www.siamchart/forum) without successful login.

My code is as following..

$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);

Edit

The forum is using vBulletin. This is the script in the login page

<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>

Am I do anything wrong? Thank you very much.

Community
  • 1
  • 1
Nick
  • 315
  • 2
  • 9
  • 17
  • If the problem still remains, http://stackoverflow.com/questions/27737350/vbulletin-curl-login-redirect-not-working#answer-27784515 might be useful. I used `php_curl` instead of `file_get_contents()` & was able to regain the login. – maan81 Jan 06 '15 at 07:38

2 Answers2

1

The site is redirecting you, but you've disabled redirection. Change that with:

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
                                          ^--
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Thanks Marc. That solved the problem. However, It seems like i still cannot get successful login. After changing the code like you suggested, I has been redirected to the login page without successful login. Not sure this is related to that the forum is using vBulletin or not. Please see my edit for the script – Nick Dec 29 '12 at 03:39
  • 1
    You should use firebug or any other utility to see the exact post request that is sent, then include all the post variables in your login request. You're better off just parsing the location header yourself and using it to determine if the login was successful or not, instead of using CURLOPT_FOLLOWLOCATION. – Michael Dec 29 '12 at 06:21
1

am working with same problem now. Your dont send md5 hashs of password, In VB it is generated at the fly, before send a login post. To prevent shiffing of open passwords information.

also here is exact list of post vars:

action="login.php?do=login" 
"vb_login_username" 
"vb_login_password" 
"s" value="" />
"securitytoken" value="guest" />
"do" value="login" />
"vb_login_md5password" />
"vb_login_md5password_utf" />

as it was in form, am trying to login now.

publikz.com
  • 931
  • 1
  • 12
  • 22
  • You should correct the code - post vars - that is being displayed. It is not being displayed properly. – maan81 Feb 19 '15 at 04:57