Jump to content

How to use $_SERVER['HTTP_REFERRER']


hno

Recommended Posts

Well, say I'm at http://www.google.com/search?q=php+help (Google search results for "php help") and I follow a link to PHP Freaks. If I do echo $_SERVER['HTTP_REFERRER'];, I'll just get http://www.google.com/search?q=php+help back. Whether that's "enough" is up to yourself of course.

 

Consider this example:

<?php
$ref = 'http://www.google.com/search?q=php+help&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:official&client=firefox-a';

$components = parse_url($ref);

if (preg_match('#^(?:www\.)?google(\.[a-z]+){1,2}$#i', $components['host']) && $path == '/search') {
parse_str($components['query'], $query);
if (isset($query['q'])) {
	echo 'Google search query: ' . htmlentities($query['q']);
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.