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

Discussion in 'PHP & Perl' started by Killswitch, Jun 7, 2010.

  1. Killswitch

    Killswitch BANNED BANNED

    Aug 9, 2009
    Likes Received:
    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.
  2. XoC--

    XoC-- Jr. VIP Jr. VIP

    Mar 5, 2009
    Likes Received:
    Obviously this isn't how you would do it exactly but I hope it points you in the right direction
    /* 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('');
      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