how to maintain session in cURL in php?

Posted by newbie programmer on Stack Overflow See other posts from Stack Overflow or by newbie programmer
Published on 2010-03-11T12:06:21Z Indexed on 2010/03/11 20:39 UTC
Read the original article Hit count: 164

Filed under:
|

how can we maintain session in cURL?

i'am having a code the sends login details of a site and logs in successfully i need to get the session maintained at the site to continue.

here is my code that used to login to the site using cURL

  <?php  
        $socket = curl_init();
        curl_setopt($socket, CURLOPT_URL, "http://www.XXXXXXX.com");
    curl_setopt($socket, CURLOPT_REFERER, "http://www.XXXXXXX.com");
    curl_setopt($socket, CURLOPT_POST, true);
    curl_setopt($socket, CURLOPT_USERAGENT, $agent);
    curl_setopt($socket, CURLOPT_POSTFIELDS, "form_logusername=XXXXX&form_logpassword=XXXXX");
    curl_setopt($socket, CURLOPT_COOKIESESSION, true);
    curl_setopt($socket, CURLOPT_COOKIEJAR, "cookies.txt");
    curl_setopt($socket, CURLOPT_COOKIEFILE, "cookies.txt");
    $data = curl_exec($socket);
    curl_close($socket); 
   ?>

© Stack Overflow or respective owner

Related posts about curl

Related posts about php