1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

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

    XoC-- Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 5, 2009
    Messages:
    211
    Likes Received:
    113
    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