shahrukh1 Posted December 4, 2012 Share Posted December 4, 2012 (edited) I need to login into this webpage in order to get the contents of a certain page that only members have access too. I decided to use cURL to do this instead of creating a stream for file_get_contents() I am pretty new to cURL, but here is my attempt at this situation. <?php $url = 'http://secure.chess.com/login'; $postfields = "c1=USERNAME&loginpassword=PASSWORD"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_USERPWD, $password); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $response = curl_exec($ch); echo $response; ?> as you may see, the webpage is chess.com/login (login url) I am pretty sure the form credentials are Username (which is name="c1") Password (which is name="loginpassword") the problem is that it replies back with "301 Moved Permanently error" Edited December 4, 2012 by shahrukh1 Quote Link to comment https://forums.phpfreaks.com/topic/271578-using-curl-to-login/ Share on other sites More sharing options...
Muddy_Funster Posted December 4, 2012 Share Posted December 4, 2012 (edited) try adding curl_setopt(CURLOPT_FOLLOWLOCATION, 1); to your options list. Edt: forgot to close tags :/ Edited December 4, 2012 by Muddy_Funster Quote Link to comment https://forums.phpfreaks.com/topic/271578-using-curl-to-login/#findComment-1397419 Share on other sites More sharing options...
Muddy_Funster Posted December 4, 2012 Share Posted December 4, 2012 just popped onto the site, and I see a couple of things : it's using https and there is another part of the form - rememberme - that your not sending. Quote Link to comment https://forums.phpfreaks.com/topic/271578-using-curl-to-login/#findComment-1397420 Share on other sites More sharing options...
shahrukh1 Posted December 4, 2012 Author Share Posted December 4, 2012 okay so I updated the script <?php $url = 'https://secure.chess.com/login'; $postfields = "c1=USERNAME&loginpassword=PASSWORD&rememberme=checked"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_USERPWD, $password); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $response = curl_exec($ch); echo $response; ?> it brings me to the login page of the chess.com website, not logged into the account, I'm assuming it is not working? sample credentials: opticalpalace : phpfreaks Quote Link to comment https://forums.phpfreaks.com/topic/271578-using-curl-to-login/#findComment-1397518 Share on other sites More sharing options...
shahrukh1 Posted December 5, 2012 Author Share Posted December 5, 2012 still unable to get it working. Quote Link to comment https://forums.phpfreaks.com/topic/271578-using-curl-to-login/#findComment-1397655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.