0

can anyone tell me whats wrong in the following code.

<?php

$username="******"; //To test type ure gmail email
$password="****"; //type ur gmail passwd 
$url="https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2"; 

$cookie="cookie.txt"; 


$postdata = "Email=".$username."&Passwd=".$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, 0); 
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);


?>

i see the login page of the website but i dont think the code passing the username and password, to do a successful login.

Edited by ITech

3
Contributors
6
Replies
11
Views
5 Years
Discussion Span
Last Post by veedeoo
0

CURLOPT_FOLLOWLOCATION, 0

When this setting is off, and your login page redirects, your curl call will stop. Try setting this to 1

0

no luck . not working after i set the following

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);

Edited by pritaeas: Code formatting

0

Hi,

you can try ...

  $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';

  ## add these items to your curl 
  curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  $post_array = array(
    "Email"=>$email,
    "Passwd"=>$password
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.