Login to a forum using php and curl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • princei2007
    New Member
    • May 2007
    • 10

    Login to a forum using php and curl

    I want to creat a weblogin client using php to login to this forum or someother.
    but i am gating with the page that u have to login befor precede.
    I am new to curl so cannot figure out where the problem is.


    [PHP]
    <?php
    $usrname="xxxxx x";
    $password="xxxx xxx";
    $loginURL="http ://www.thescripts. com/forum/login.php?do=sh owlogin";
    $reffer="http://www.thescripts. com/forum/usercp.php?";
    $cookiepath="/tmp/cookielog";
    $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
    $ch = curl_init();
    curl_setopt($ch , CURLOPT_COOKIEJ AR, $cookiepath);
    curl_setopt($ch , CURLOPT_URL,$lo ginURL);
    curl_setopt($ch , CURLOPT_USERAGE NT, $agent);
    curl_setopt($ch ,CURLOPT_POST,1 );
    curl_setopt($ch ,CURLOPT_POSTFI ELDS,'vb_login_ username='.$usr name.'&vb_login _password='.$pa ssword);
    ob_start();
    curl_exec($ch);
    ob_end_clean();
    curl_close ($ch);
    unset($ch);
    $ch = curl_init();
    curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
    curl_setopt($ch , CURLOPT_COOKIEF ILE, $cookiepath);
    curl_setopt($ch , CURLOPT_URL,$re ffer);
    $result = curl_exec ($ch);
    print $result;
    curl_exec($ch);
    curl_close ($ch);
    ?>

    [/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Could you be more specific with what you're trying to accomplish here? Are you creating an auto-login script for your own personal use, or is this something you want to eventually put on a publicly-accessible website?

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      The biggest problem you have here is that you are not collecting and setting the user COOKIES for the site you are trying to connect to.

      Comment

      • princei2007
        New Member
        • May 2007
        • 10

        #4
        This manily for my Learning Perpose i mentioned early that iam new in curl and php also oviously for my personal use not for any public use.
        yes iam collection cookies by curl cookiejar option and store the cookies in /tmp .That is what i understand to use curl with cookies , i donot have any detailed idea.

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          Take a look at the form variables that are being sent to the login page. There are a few more than the ones you are POSTing.

          Comment

          • princei2007
            New Member
            • May 2007
            • 10

            #6
            i have no idea how to post those hidden fields coz they may have certain value embeded and also they have md5hasing which php have a function of md5 but how to use those .

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Originally posted by princei2007
              i have no idea how to post those hidden fields coz they may have certain value embeded and also they have md5hasing which php have a function of md5 but how to use those .
              The chore of your project will be figuring these things out, watching (with Wireshark perhaps) what is getting POSTed and emulating that in your application.
              MD5 is easy, just call it:

              [code=php]
              $pass = "dumb passphrase";
              $md5pass = md5($pass);
              [/code]

              Comment

              • princei2007
                New Member
                • May 2007
                • 10

                #8
                how to find out what is gating posted

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  Originally posted by princei2007
                  how to find out what is gating posted
                  Wireshark is my favorite tool, but you could always use Fiddler. Fiddler is a bit more straightforward , and, it is designed with HTTP in mind.

                  Comment

                  Working...