Jump to content

Curl and login


graham23s

Recommended Posts

Hi Guys,

 

i am trying to automatically loginto my webmail using curl, i have my code like:

 

<?php
  $id = "xxxx"; 
  $pw = "xxxxxx"; 
  $postfields = "login_username=$id&secretkey=$pw&submit=Login"; 
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_HEADER, 1); // Get the header 
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection 
  curl_setopt($ch, CURLOPT_COOKIEJAR, "curl/cookie.txt"); 
  curl_setopt($ch, CURLOPT_URL, "http://webmail.website.co.uk/src/login.php"); 
  curl_setopt($ch, CURLOPT_POST, 1); 
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields"); 

  curl_exec($ch); 
  curl_close($ch);
  
  print_r($ch); 

  print("<iframe width=\"95%\" height=\"700px\" scrolling=\"auto\" frameborder=\"1\" bordercolor=\"#000000\" src=\"$ch\"></iframe><br /><br />");
?>

 

 

all this seems to do ius diaplay me the page not logged in! i have edited out the site name :)

 

am i doing something wrong at all?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/131533-curl-and-login/
Share on other sites

by using CURL, you are authenticating and starting a session from your server to the webmail...the iframe that you print after is for your browser to the webmail (which is a different session).

 

i would recommend something like Greasemonkey if you are trying to auto-authenticate yourself

Link to comment
https://forums.phpfreaks.com/topic/131533-curl-and-login/#findComment-683182
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.