can anyone tell me whats wrong in the following code.


$username="******"; //To test type ure gmail email
$password="****"; //type ur gmail passwd 


$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: Gecko/20070725 Firefox/"); 
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;  



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

Recommended Answers

All 6 Replies


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


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(
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, learning, and sharing knowledge.