cURL: check to see if login is correct before continuing?

Killswitch

BANNED
Joined
Aug 9, 2009
Messages
14
Reaction score
5
Alright, I know my way around PHP pretty damn well, it could be because it's 2AM and I'm tired as hell, but I'm trying to figure out if this is possible.

Use cURL to take user/pass from a form, and login to squirrelmail and see if it was successful, if it is, take them to the inbox like if they would have logged in, if not, return them to a custom error page.

Am I barking up the wrong tree trying to figure this out, or is it possible? And if so, how do I go about doing that?

Thanks in advance for anyone who's trying to help.
 
Obviously this isn't how you would do it exactly but I hope it points you in the right direction
Code:
/* I'm not sure if you meant take a value from a form or fill it but here's how you could take it.. */
  $content = '<input type="text" name="user" value="Killswitch" />';
  preg_match('/type="text name="user" value="(.+?)"/', $content, $matches);
  $user = $matches[1];

  $fields = array (user => $user, hiddenvalue1 => login);

  $ch = curl_init('http://www.example.com/squirrel/login.php');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookiefile.txt'); 
  curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookiefile.txt'); 
  $ret = curl_exec($ch);

  if(strstr("Login Failed Message", $ret)) {
    echo "Login Failed!";
  } else {
   /* Proceed with curl to GET inbox url */
  }

It shouldn't be too tricky to login to Squirrelmail, you'll want to get LiveHTTP Headers for FireFox and watch what it posts/gets when you login
 
Back
Top