http_referer question

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
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

http_referer question

Post by jaymoore_299 »

I made a page to record the http_referer of all visitors to a webpage. It seems to work for most cases, but when I try it myself I find that the value is not filled in for my own visits.

Is this value only filled in when I come to that page through a link from a different page? What other cases would this be left empty?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: http_referer question

Post by foobar »

jaymoore_299 wrote: Is this value only filled in when I come to that page through a link from a different page?
Yes, that's the whole point of an HTTP_REFERER. It holds the url of the page that referred you to the one you're on.

On a side note, using HTTP_REFERERS for anything else than non-crucial statistics (read: fun facts) isn't a good idea. The HTTP_REFERER, as the name states, is sent int he HTTP request, which can be easily altered to show a different url. What the browser can do, you can do to.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yep. Altered, or not even sent at all.

So make sure to add an if statement to check if it does exist, because you may have an error if you simply refer to it.
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

this is part of what i use to track users on my site

Code: Select all

//whats their IP
  $host = $_SERVER['REMOTE_ADDR'];
  //where did they come from
  $uri = $_SERVER['HTTP_REFERER'];
  //what page are they requesting
  $page = $_SERVER['REQUEST_URI'];
  //what browser agent are they using
  $browser = $_SERVER['HTTP_USER_AGENT'];

   if ( $host == 'my.ip.here' )
   { 
      //so i dont include myself in the stats
     //only works if IP stays the same
     }else{
insert stats to db here
}
So it will tell me initially who referred them, then once on site
it shows what page they are on and what page they were previously on.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

User agent is just as unreliable as Referer
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

Sami wrote:User agent is just as unreliable as Referer
for my stats purposes it doesnt matter.

if i needed to control security, then obvisiouly that route
would not be used.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Agreed.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

blacksnday wrote:
Sami wrote:User agent is just as unreliable as Referer
for my stats purposes it doesnt matter.

if i needed to control security, then obvisiouly that route
would not be used.
As I said, as long as you don't use HTTP data from the client for anything but fun-facts, you're fine.

Err...what was it you wanted to know? :oops:
Post Reply