tags:

views:

1904

answers:

3

I have a PHP script that does an HTTP request on behalf of the browser and the outputs the response to the browser. Problem is when I click the links from the browser on this page it complains about cookie variables. I'm assuming it needs the browsers cookie(s) for the site.

how can I intercept and forward it to the remote site?

A: 

The Cookie is usually sent with the HTTP request header like

Host stackoverflow.com
User-Agent ...
Accept-Language en-us,en;q=0.5
Referer http://stackoverflow.com/unanswered
Cookie bla=blabla;blubb=blu

So I guess that just have to modify the cookie part in your header.

Daff
+1  A: 

From curl_setopt:

By default, libcurl always stores and loads all cookies, independent if they are session cookies or not.

However you may need to set cookies directly, which can be done using:

curl_setopt($ch, CURLOPT_COOKIE, 'foo=bar');

Which is the same as the Set-Cookie HTTP header. Check you're not using curl_setopt($ch, CURLOPT_COOKIESESSION, true) as this will make libcurl ignore some cookies.

Ross
+2  A: 

You can't.

If you curl the request, you will need to parse the output, and replace all links so they go thru your server.

  www.yourdomain.com/f?=www.someotherdomain.com/realpage

The only way this would work is if you use persistent cookies in your curl request. CURL can keep cookies itself. Assign a session ID to the cookie file (in curl) so subsequent requests get the same cookies. When a user clicks a link, you will need to curl the request again.

It is a security issue to allow site1 to set cookies for site2. Imagine if you could set cookies in the browser for paypal and trick the user into thinking they had logged int or some other malicious action.

Byron Whitlock
It seems like I should find a more standard solution like auto redirect or something. Thanks
Hannes de Jager