Page 1 of 1
Display the top referers on my website
Posted: Wed Nov 15, 2006 1:24 pm
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
Posted: Wed Nov 15, 2006 1:30 pm
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.
Posted: Wed Nov 15, 2006 1:41 pm
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?
Posted: Wed Nov 15, 2006 1:45 pm
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
Posted: Wed Nov 15, 2006 1:52 pm
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.
Posted: Wed Nov 15, 2006 1:55 pm
by Luke
Well if you have questions... ask away.
Posted: Wed Nov 15, 2006 2:02 pm
by netpants
so something like this?
Code: Select all
if ( $referer != "http://www.mysite.com" )
{
INSERT INTO Referer (refererURL)
VALUES ($referer)
}
else
{
die
}