Grabbing referer info

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Grabbing referer info

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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]
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Post by therat »

Thanks, works perfectly.
Post Reply