Re: How to pass set-cookie header to browser

Stephen Pynenburg <[email protected]>
Newsgroups gmane.comp.web.curl.php
Message-ID <[email protected]>
There might be a way to do it with curl, but the only way that comes to mind
at the moment is with native PHP code - parse the cookies you need from
cookie.txt, then just use header("Set-Cookie: name=value"); as necessary.
Again, it's not the tidiest solution, but it works.
-Stephen

On Sun, Sep 13, 2009 at 09:20, <[email protected]> wrote:

> Hi,
>
> I have the following code:
> <?php
>        $cookie_file=dirname(__FILE__).'/cookie.txt';
>        $url='http://rednet.imdnet.hop.clickbank.net/';
>
>        $ch = curl_init();
>        curl_setopt($ch,CURLOPT_URL,$url);
>        curl_setopt($ch,CURLOPT_TIMEOUT,30);
>        curl_setopt($ch,CURLOPT_MAXREDIRS,4);
>        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
>        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
>        curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
>        curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
>        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
>        curl_setopt($ch, CURLOPT_ENCODING, '');
>        curl_setopt($ch, CURLOPT_HEADER, TRUE);
>        curl_setopt($ch, CURLOPT_NOBODY, TRUE);
>
>        $header = curl_exec($ch);
>        $result=curl_getinfo($ch);
>
>        curl_close($ch);
>
>        header('Location: '.substr($result['url'], 0, strpos($result['url'],
> '?hop=')))
>
> ?>
>
> The aim of code is to get the final url, strip ?hop= part from url, and
> redirect browser to that url. It works fine, and redirects to the correct
> url. However, its not passing the cookie information to the browser.
> Cookie info is saved in cookie.txt file. How do I pass that cookie data to
> the browser?
>
> Thanks,
> Peter
>
>
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.