cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: How to pass set-cookie header to browser

From: Stephen Pynenburg <spynenburg_at_gmail.com>
Date: Sun, 13 Sep 2009 10:55:14 -0400

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, <info_at_itegic.co.za> 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
Received on 2009-09-13