prady Posted May 13, 2009 Share Posted May 13, 2009 <?php> $login = "https://www.google.com/accounts/ServiceLoginAuth?service=mail"; $c = curl_init(); curl_setopt($c, CURLOPT_URL, $login); curl_setopt($c, CURLOPT_COOKIEJAR, "cookies.txt"); curl_setopt($c, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($c, CURLOPT_POST, 1); curl_setopt($c, CURLOPT_POSTFIELDS, "username=myusername&password=mypassword"); curl_setopt($c, CURLOPT_RANGE, "0-4096"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // return to var curl_setopt($c, CURLOPT_FAILONERROR, 1); // dont hang curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($c, CURLOPT_TIMEOUT, 3); // time out after 3s curl_setopt($c, CURLOPT_HEADER, 0); $login_done = curl_exec($c); ?> i want to login to gmail using curl php. the code works for some other account; But i m not able to use it for gmail . I want to see the inbox. that is after logging in thru this Quote Link to comment https://forums.phpfreaks.com/topic/158009-php-curl-function-help-please/ Share on other sites More sharing options...
Maq Posted May 13, 2009 Share Posted May 13, 2009 What happens? Are there any errors? Please use tags around code. Quote Link to comment https://forums.phpfreaks.com/topic/158009-php-curl-function-help-please/#findComment-833511 Share on other sites More sharing options...
prady Posted May 14, 2009 Author Share Posted May 14, 2009 <?php> $login = "https://www.google.com/accounts/ServiceLoginAuth?service=mail"; $c = curl_init(); curl_setopt($c, CURLOPT_URL, $login); curl_setopt($c, CURLOPT_COOKIEJAR, "cookies.txt"); curl_setopt($c, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($c, CURLOPT_POST, 1); curl_setopt($c, CURLOPT_POSTFIELDS, "username=myusername&password=mypassword"); curl_setopt($c, CURLOPT_RANGE, "0-4096"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // return to var curl_setopt($c, CURLOPT_FAILONERROR, 1); // dont hang curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($c, CURLOPT_TIMEOUT, 3); // time out after 3s curl_setopt($c, CURLOPT_HEADER, 0); $login_done = curl_exec($c); ?> all i get is a blank page after that, when clicked. But i tried a different URL and it works that time. But for gmail it is not working. can anyone tell me what is wrong with this code Quote Link to comment https://forums.phpfreaks.com/topic/158009-php-curl-function-help-please/#findComment-833775 Share on other sites More sharing options...
Ken2k7 Posted May 14, 2009 Share Posted May 14, 2009 I think you're missing *A LOT* of data. Gmail has a ton of hidden input fields. Not sure what they are or what they mean though. Also, I didn't see a username or password field. I think you got those field names wrong. Quote Link to comment https://forums.phpfreaks.com/topic/158009-php-curl-function-help-please/#findComment-833779 Share on other sites More sharing options...
cunoodle2 Posted May 14, 2009 Share Posted May 14, 2009 They may also be redirecting a few pages in. Try adding the following value as well.. curl_setopt($c, CURLOPT_MAXREDIRS, 4); I also think that Ken2k7 is right in that you are missing quite a bit of other fields/data Quote Link to comment https://forums.phpfreaks.com/topic/158009-php-curl-function-help-please/#findComment-833845 Share on other sites More sharing options...
prady Posted May 14, 2009 Author Share Posted May 14, 2009 <?php> $login = "https://www.google.com/accounts/ServiceLoginAuth?service=mail"; $c = curl_init(); curl_setopt($c, CURLOPT_URL, $login); curl_setopt($c, CURLOPT_COOKIEJAR, "cookies.txt"); curl_setopt($c, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($c, CURLOPT_POST, 1); curl_setopt($c, CURLOPT_POSTFIELDS, "Email='ppradeepkumar2006'& Passwd='puppyhead'& continue='http://mail.google.com/mail/?ui=html&zy=l'& service='mail'& rm='false'& ltmpl='false'& h1='en'& ltmpl='default'& scc='1'& GALX='8eKZr_QRh9E'"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_RANGE, "0-4096"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // return to var curl_setopt($c, CURLOPT_FAILONERROR, 1); // dont hang curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($c, CURLOPT_TIMEOUT, 3); // time out after 3s curl_setopt($c, CURLOPT_HEADER, 0); $login_done = curl_exec($c); echo $login_done; ?> i tried to find the fields in gmail's source HTML file..i added the fields whichever was missing. but still im not able to pass thru Quote Link to comment https://forums.phpfreaks.com/topic/158009-php-curl-function-help-please/#findComment-833939 Share on other sites More sharing options...
cunoodle2 Posted May 14, 2009 Share Posted May 14, 2009 You should change your username and password. They are in plain text in your code. I just tried them and they do infact work on gmail.com. Hurry up and change your stuff before someone gets into there and does bad things to your account. Quote Link to comment https://forums.phpfreaks.com/topic/158009-php-curl-function-help-please/#findComment-834290 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.