tags:

views:

169

answers:

4

is it possible to send referer information with php?

A: 

Yes, when trying to load a page, just write the Referer header to the output stream.

SHiNKiROU
+5  A: 

If you are, for example, fetching the contents of a URL in PHP using cURL, you can send any additional headers you want, including a referrer header.

You can not force the users browser to send a referrer header by any means, especially not with a server side language.

deceze
A: 

Referer is a 'request' header meaning sent by the client i.e. browser. From server side i.e. using PHP you can only control 'response' headers.

If you are planning to make HTTP requests with PHP, that is different of course.

Edit: ..and requests made from the server to the other servers is a pretty common scenario actually. It seems like you should be able to set the headers you want while creating the HttpRequest:

$options = array(headers => $header_array,
                 httpauth => $credentials);
$r = new HttpRequest($url, HTTP_METH_POST, $options);

Or you can use the addHeaders method:

$r->addHeaders(array('Referer' => 'http://example.com'));
Maxwell Troy Milton King
Unless you use PHP to request a page with `fopen($url)` or curl...
Josh
How popular is PHP as 'scripting' environment? Wow, times have changed..
Maxwell Troy Milton King
@Maxwell - I use PHP on the server to make requests to other servers often. See RPC, SOAP, etc
Josh
Thank you @Josh.
Maxwell Troy Milton King
If people who are giving negative feedback could drop a note to say what is wrong with the answer, that would be nice. I don't want to leave a misleading answer online.
Maxwell Troy Milton King
@Maxwell: I removed my downvote, but you're receiving negative feedback because "No it's not possible from the server side while serving pages" is incorrect. I understand what you're trying to say but that statement doesn't say it. Your second paragraph makes much more sense.
Josh
In fact if you kill the first paragraph and change "If you are planning to use it from client side" to "If you are planning to make HTTP requests with PHP" or something similar then you have one of the best answers here and I would happily upvote.
Josh
@Josh that makes sense. Thanks again.
Maxwell Troy Milton King
I've given you +1. If anyone else is following this and has voted @Maxwell down, you may want to change your votes as this is now a valid answer.
Josh
Just stumbled across this answer and though it deserved a +1.
alex
+3  A: 

It's not possible to get the client browser to send a different Referer header.

However, it is theory possible for you to do this when conducting an HTTP request from PHP (either using cURL or native URL wrappers), but including a custom request header in this request.

thomasrutter