Page 1 of 1
how to show the 5 latest referer's site url ?
Posted: Sun Aug 08, 2010 9:29 am
by everydayrun
i use this code to show where the visitors came from to my site.
Code: Select all
<?php$referer=$_SERVER['HTTP_REFERER'];echo $referer;?>
now, i want to show the 5 latest vistors referer's site url on my site ?
Re: how to show the 5 latest referer's site url ?
Posted: Sun Aug 08, 2010 9:34 am
by MindOverBody
On each visit, save referer url to database or a file, and when needed fetch that data from it.
Re: how to show the 5 latest referer's site url ?
Posted: Sun Aug 08, 2010 9:40 am
by everydayrun
MindOverBody wrote:On each visit, save referer url to database or a file, and when needed fetch that data from it.
if i put each url into a database table, with the time going , the table will become larger and larger.so, i want to let the database only save one day 's records。 when a new day comes, the old day's record will be deleted. is there a way to get this?
Re: how to show the 5 latest referer's site url ?
Posted: Sun Aug 08, 2010 10:04 am
by MindOverBody
Yap, on database table, add column timestamp, and when inserting data into table, insert time stamp, and delete all where date('d', $timestamp_from_table) is not equal date('d', time()).
You will achieve that in your database refferers table will be only that day's inserts. Of course, you can play with this to achieve much more precise goal. Hope you understaned me

Re: how to show the 5 latest referer's site url ?
Posted: Sun Aug 08, 2010 10:15 am
by everydayrun
MindOverBody wrote:Yap, on database table, add column timestamp, and when inserting data into table, insert time stamp, and delete all where date('d', $timestamp_from_table) is not equal date('d', time()).
You will achieve that in your database refferers table will be only that day's inserts. Of course, you can play with this to achieve much more precise goal. Hope you understaned me

i am sorry, i don't know how to set the timestamp colum and the initial value. could you write the line down.thank you!
Re: how to show the 5 latest referer's site url ?
Posted: Sun Aug 08, 2010 10:30 am
by MindOverBody
First, you add column to your referer database table called 'time' for example.
Code: Select all
function add_referer(){
//connect to your database here
// Add referer to database table with current time formated to insert only number of day in month
mysql_query("INSERT INTO db_table_name (referer, time) VALUES ('" . $_SERVER['HTTP_REFERER'] . "','" . date('d', time() ) . "')");
// now delete all table inserts which are not todays
mysql_query("DELETE FROM db_table_name WHERE time<>'" . date('d', time() ) . "' ");
}
So that is function that will add new referer, and delete all the others which are not made on that same day.