Page 1 of 1

Grabbing referer info

Posted: Wed Jan 28, 2004 4:03 pm
by therat
I am using this code to store the referer in a database.

Code: Select all

if (isset($_SERVER['HTTP_REFERER'])) {
	$refer = $_SERVER['HTTP_REFERER'];
 }else {
	$refer = ' [ -- Direct Hit -- ] ';
 }
This stores the whole URL in the database. What I want is to store the domain name only. How do I change the above to acheive this.

Posted: Wed Jan 28, 2004 4:39 pm
by Weirdan

Code: Select all

if (isset($_SERVER['HTTP_REFERER'])) { 
   $parsed_url=parse_url($_SERVER['HTTP_REFERER']);
   $refer = $parsed_url["host"]; 
}else { 
   $refer = ' [ -- Direct Hit -- ] '; 
}
[php_man]parse_url[/php_man]

Posted: Thu Jan 29, 2004 1:16 pm
by therat
Thanks, works perfectly.