PHP Referrer – HTTP Referrer

by Hiroshi on June 16, 2008

in Redirection, Referrer, URL

Suppose user submits a form and post data to the other page. We can find out its referrer URL (From where he came?) for redirection or other purpose.
Referrer can be used in following ways.

  • Redirection (Redirect back from where the form was posted, lets say after mailing…)
  • To referrer a web page to a friend.

HTTP Referrer


Printing HTTP Referrer

echo "$ref";

Redirection With HTTP Referrer

$ref = @$HTTP_REFERER;
// print $ref;
header ("location:".$ref);

*** Redirection With HTTP Referrer While Globals Are Off ***

header ("location:".$ref);

For more reference on this proceed here.

Variable $ref contains the value of referring page.

Consider Redirection After Mail Script

if ($fromEmail)
if ($fromName=='')
$subject= "Your friend has referred you this link from";
$subject= "$fromName has referred you this link from";
$message = "
Dear $toName,
Your friend $fromName has referred this link to you.
Please visit this link by clicking $ref
$from = "From: $fromEmail\r\n";
mail($toEmail, $subject, $message, $from);
header ("location:".$ref);

Download HTTP Referrer Script

Related Posts

Previous post:

Next post: