$HTTP_REFFERER

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
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

$HTTP_REFFERER

Post by Mr Tech »

Lets say this pages linked to my website

domain.com
domain.com/page.php
domain.com/anotherpage.html

Using $HTTP_REFFERER to find that they have sent a click to my website, how do I remove everything after the slash so I can match domain.com with my records?
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Post by lazersam »

Code: Select all

$home = "domain.com";

$refer = substr($HTTP_REFERER, 0, strlen($home));
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

have a look at the parse_url function
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

That substr code seem to return http://www no matter what site links to me...

How would I use the parse_url funcrion?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

domain.com/page.php

Code: Select all

$splitUrl = parse_url($HTTP_REFFERS);
echo $splitUrl['host'];
//should echo out domain.com
lots of info in the manual for parse_url
Post Reply