cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to strip cookies from header responce and save on client machine

From: Tom Van de Putte <goldfrapper_at_gmail.com>
Date: Fri, 11 Sep 2009 01:12:57 -0700

If however what you want if to use the cookie for following requests you can
set

curl_setopt($_h, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($_h, CURLOPT_COOKIEFILE, 'cookies.txt');

On Fri, Sep 11, 2009 at 1:10 AM, Tom Van de Putte <goldfrapper_at_gmail.com>wrote:

> Put every header in an array and the select the setcookie header:
>
> $headers = array();
> foreach( explode("\r\n", substr($buffer,0,strpos($buffer,"\r\n\r\n")) ) as
> $header) {
> if(substr($header,0,4)=='HTTP') continue;
> $headers[substr($header,0,strpos($header,':'))] =
> trim(substr($header,strpos($header,':')+1));
> }
>
> $cookie = $headers['Set-Cookie'];
>
> Btw, curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); will not work depending
> on the settings in php_ini: Best is to act on redirects yourself by using
> the location headers content as the url for a new curl request.
>
> Tom,
>
>
> On Thu, Sep 10, 2009 at 9:24 AM, <info_at_itegic.co.za> wrote:
>
>> I have following code:
>>
>> <?php
>> $ch = curl_init("http://xxxx.imdnet.hop.clickbank.net/");
>> curl_setopt($ch, CURLOPT_NOBODY, true);
>> curl_setopt($ch, CURLOPT_HEADER, true);
>> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
>> curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
>>
>> $buffer = curl_exec($ch);
>> curl_close($ch);
>>
>> echo ($buffer);
>> ?>
>>
>> which returns:
>>
>> HTTP/1.1 301 Moved Permanently Date: Thu, 10 Sep 2009 16:09:18 GMT Server:
>> Apache Set-Cookie:
>> p=861971CF5CD0372717109825575495A2D3AE2543850A66DC9F3933A1C8D1CFDE;
>> Domain=.clickbank.net; Expires=Tue, 09-Mar-2010 16:09:18 GMT; Path=/
>> Cache-Control: no-store Pragma: no-cache Expires: 0 P3P: CP="ADM OUR IND
>> COM" Location:
>>
>> http://xxxx.imdnet.hop.clickbank.net/hop/?CBRehoppp2=http%3A%2F%2Fwww.HowToGetHimBackFast.com%3Fhop%3Dxxxx&vend=imdnet&code=1000000000000000&affi=rednet&hfid=&parms=&key=688C87FC4D8DEF594642913BA11CDE79
>> Connection: close Content-Type: text/html;charset=ISO8859_1 HTTP/1.1 301
>> Moved Permanently Date: Thu, 10 Sep 2009 16:09:18 GMT Server: Apache
>> Cache-Control: no-store Pragma: no-cache Expires: 0 P3P: CP="ADM OUR IND
>> COM" Connection: close Location:
>> http://www.HowToGetHimBackFast.com?hop=xxxx Content-Type:
>> text/html;charset=ISO8859_1 HTTP/1.1 200 OK Date: Thu, 10 Sep 2009
>> 16:09:18 GMT Server: Apache/2.2.13 X-Powered-By: PHP/5.2.10 Set-Cookie:
>> PHPSESSID=12b27c4401f66621aec02c967769bfbe; path=/ Expires: Thu, 19 Nov
>> 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate,
>> post-check=0, pre-check=0 Pragma: no-cache Accept-Ranges: bytes
>> Content-Length: 68357 Content-Type: text/html; charset=utf-8
>>
>>
>> How do I strip the "Set Cookie" part from the header, and actually save
>> the cookie on the user machine? Also, how can I make the final redirect
>> "http://www.HowToGetHimBackFast.com?hop=xxxx" to open on client browser
>> as
>> "http://www.HowToGetHimBackFast.com"?
>>
>> Thanks,
>> Peter
>>
>>
>>
>
>
> --
> -- Tom Van de Putte
>

-- 
-- Tom Van de Putte
Received on 2009-09-11