views:

53

answers:

2

I am using javascript to get the referring page (document.referrer) which works fine and I can add this value to a div no problem.

How do I assign this value to a PHP variable in order to do some other things with it?

Ideally, something like:

$myphpvariable  = document.referrer;
+4  A: 

You can use

$_SERVER['HTTP_REFERER']

and since this is PHP this happens on the server side.

More info: $_SERVER in PHP

As a side note REFERER is sent by the user agent as part of the HTTP request - do not rely on it to be truthful!

codaddict
Please notice that array keys are case-sensitive so `HTTP_referer` and `HTTP_REFERER` are two different things.
Crozin
Here the $_SERVER came handy, but consider a situation where i want to pass a javascript value to a PHP variable.. How can i do that?
kvijayhari
+3  A: 

what about

$myphpvariable = $_SERVER['HTTP_REFERRER'];

?

Ubersoldat
nope - it's `HTTP_REFERER` - yours is spelled correctly in English, but not for PHP (see http://en.wikipedia.org/wiki/HTTP_referrer)
Dominic Rodger
thanks much appreciated - works like a charm
Jonathan Lyon
codaddict answered even before Uberslodat, and both seems to be the same, But only one as accepted answer!! seems there should be option in stackoverflow to mark more than one post as accepted answer. (Consider that two people have given two different techniques for a single problem and both has been a good solution)
kvijayhari