Re: [PHP 5.2.8] Retrieve cookies from remote host and pass them back to client.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 13, 2009 at 1:03 PM, Andrew Ballard <aballard@xxxxxxxxx> wrote:
> On Fri, Feb 13, 2009 at 12:42 PM, Jason Cipriani <jason.cipriani@xxxxxxxxx>
> wrote:
>>
>> I have a PHP 5.2.8 web application that needs to retrieve a resource
>> from a remote URL. However, the remote host also sends a cookie back
>> (in a Set-Cookie header), and I need to grab that cookie and pass it
>> on to the client (so that it's stored by the client browser). I do
>> know the name of the cookie beforehand.
>>
>> What is the best way to do this? Passing a cookie from PHP back to the
>> client is easy, it's grabbing the cookie from the remote URL that is
>> the problem.
>>
>> There is no support for cookies in file_get_contents(), so that won't
>> work. I can use curl to retrieve the remote URL with headers, but curl
>> does not seem to provide an easy way to get the value of the cookie
>> beyond retrieving the HTTP headers and parsing them manually. I could
>> use and parse curl's cookie file (another hack) but the cookie
>> contains a value that is randomly generated, and the cookies in curl's
>> cookie jar are global to all PHP requests (so if multiple users made
>> the same request, their cookie value could be shared).
>>
>> How can I retrieve the contents of a remote resource as well as the
>> value of a cookie sent with that resource?
>>
>> Thanks,
>> Jason
>>
>> P.S.: Also, as a minor side question; how, if at all, would the method
>> for doing this be different in PHP 4.4.9?
>>
>
> I usually use the HttpRequest for this type of stuff, but it only works with
> PHP 5.0/5.1 and greater. Otherwise, CURL is the next easiest, followed by
> direct socket connections.

Thanks! This is exactly what I was looking for. I've managed to get
everything working well with HttpRequest.

Cheers,
Jason

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux