SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cURL + Session IDs

    Hi All,

    I'm trying to learn curl and I've run into a bit of a problem. I'm having the script login to an affiliate program of mine, but the POST isn't working because a session ID is attached to the POST url in the login form and I don't know how to grab that session ID and attach it.

    My URL looks like this:
    PHP Code:
    http://www.affiliate.com/production/index.cfm?changestate=login 
    But the real url in the action of the form has "index.cfm?changestate=login&session=123456".

    How can I append this extra bit of info to make my login work? As of now it just brings me back to the main page and doesn't even attempt a login.

    So my code looks like this:

    PHP Code:
       <?php
       
       $cookie_file 
    "/home/domain/www/writedir/test.txt";
       
    $url "http://www.affiliate.com/production/index.cfm?changestate=login";
       
    $agent "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1";
       
       
    $username urlencode("username");
       
    $password "password";
       
       
    $ch curl_init();    // initialize curl handle
       
    curl_setopt($chCURLOPT_URL,$url); // set url to post to
       
    curl_setopt($chCURLOPT_FAILONERROR1);
       
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);// allow redirects
       
    curl_setopt($chCURLOPT_RETURNTRANSFER,1); // return into a variable
       
    curl_setopt($chCURLOPT_POST1);
       
    curl_setopt($chCURLOPT_POSTFIELDS"username=$username&password=$password"); // add POST fields
       
    curl_setopt($chCURLOPT_COOKIEFILE$cookie_file);
       
    curl_setopt($chCURLOPT_COOKIEJAR$cookie_file);
       
    curl_setopt($chCURLOPT_USERAGENT$agent);
       
    curl_setopt($chCURLOPT_TIMEOUT3); // times out after 4s
       
       
       
    $result curl_exec($ch); // run the whole process
       
    curl_close($ch);
       
       print 
    $result;
       
    ?>

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Snoopy might be able to take some of the work out of doing things like this for you:
    http://snoopy.sourceforge.net/

    Good luck whichever way you go.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •