Posting form with curl that requires work with sessions?

Discussion in 'PHP' started by Macmee, Apr 16, 2009.

  1. #1
    I've written this code to submit a POST form:

    (please bare with me, this is an example)
    <?php
       $url = 'logging.php';
       $params = "id=dave&password=changeme&lang=USENG";
       $user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)";
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_POST,1);
       curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
       curl_setopt($ch, CURLOPT_URL,$url);
       curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
       $result=curl_exec ($ch);
       curl_close ($ch);
    ?>
    
    Code (markup):
    That would work, but then it doesn't work because when you initially go to the logging.php page it creates a session. Since Curl doesn't have that session the from cannot be logged into. Is there a way to capture the session from the logging.php page, then use curl to submit the form?
     
    Macmee, Apr 16, 2009 IP