How to save Cookies from a remote site with Curl?

Asked

Viewed 997 times

2

I’m having trouble saving and reading cookies from a remote site I’m opening with Curl:

            $cr = curl_init($this->_URL);
            curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($cr, CURLOPT_USERAGENT, $useragent );           
            curl_setopt($cr, CURLOPT_COOKIEFILE, 'cookie.txt');   
            $html = curl_exec($cr); 
            curl_close($cr); 

I’ve tried to COOKIEJAR etc, but it doesn’t work!

The site I am opening in Curl, saves cookies when we click on a certain value, this cookie is later read by another file of the site, tested with the proxy of the Glype project, and works perfectly, it saves the cookie, even if I open the site by my cURL and accessing the file that reads the cookies by the glype proxy that is on the same server, it finds the cookies, but my Curl does not think!

How I save and later read cookies from a remote site using Curl?

  • 1

    According to this topic (http://stackoverflow.com/questions/19295586/why-php-curl-does-not-save-cookie-in-my-cookiefile) You need to use the absolute path to save a cookie. curl_setopt ($ch, CURLOPT_COOKIEJAR, realpath($cookie_file) );

  • 1

    already tried to capture by header? curl_setopt($ch, CURLOPT_HEADER, 1); curl_getinfo($ch, CURLINFO_HTTP_CODE);

  • I tried yes, but it doesn’t work! I don’t know what can be wrong.

1 answer

2


Browser other questions tagged

You are not signed in. Login or sign up in order to post.