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.

CURLOPT_FOLLOWLOCATION, 0

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

no luck . not working after i set the following

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);

Have a look at this SO thread. There is a working example. You can compare to your code and see what is missing.

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); 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.