Display the top referers on my website

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
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Display the top referers on my website

Post by netpants »

Hi ,
I am new to PHP and am self teaching myself. i understand the basics of getting info into a MYsql database, and retrieving it, and how to use variables and arrays. But I am trying to make a script that will grab refers to my site and display them on my website in order from most hits to least hits. I was wondering , what is the code to grab referes from other sites to display the url of the sites, or the name of the sites refereing to my site. I have used code other people have made but I would like to use my own. Any help would be appreciated .
Thanks
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Why? To invite spammers to your website?

You can get the referer with $_SERVER['HTTP_REFERER'] but the value isn't always there to be grabbed (not in the header) and I believe it's very easily spoofed.
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Post by netpants »

Actually the top refferes would be displayed on like an admin page so only the admins will see it, but I want to see how people are linking to the site and which sites are actually driving in the traffic. It is for my own knowledge and I will use the info to find out what kind of sites are driving in the most traffic.

So I would use $_SERVER['HTTP_REFERER'] so would I make a variable like $referer = "$_SERVER['HTTP_REFERER']";
and then call teh variable in an echo statement? echo $referer; - Or is there a way to write the refferer to a database and have them display in order from most refered to least refered?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

netpants wrote:Actually the top refferes would be displayed on like an admin page so only the admins will see it, but I want to see how people are linking to the site and which sites are actually driving in the traffic. It is for my own knowledge and I will use the info to find out what kind of sites are driving in the most traffic.
I see :)
netpants wrote:So I would use $_SERVER['HTTP_REFERER'] so would I make a variable like $referer = "$_SERVER['HTTP_REFERER']";
that's

Code: Select all

$referer = $_SERVER['HTTP_REFERER'];
netpants wrote:and then call teh variable in an echo statement? echo $referer; - Or is there a way to write the refferer to a database and have them display in order from most refered to least refered?
Well of course... store the value and then add it to a table...

http://www.Yoursite.com/somepage.php:

Code: Select all

$referer = $_SERVER['HTTP_REFERER'];
// If referer != yoursite
// Save referer to database
admin.php

Code: Select all

// Load most common referers from db and display them for admins
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Post by netpants »

Thanks for your help, I think I can work with the info you gave me. See I am still new and do not have it lodged into my memory all of the different things php can do and how to accomplsih them.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Well if you have questions... ask away.
netpants
Forum Commoner
Posts: 39
Joined: Wed Nov 15, 2006 1:21 pm

Post by netpants »

so something like this?

Code: Select all

if ( $referer != "http://www.mysite.com" )

{

INSERT INTO Referer (refererURL)
                  VALUES ($referer)
}
else
{
die
}
Post Reply