Introduction
ah! counting visitors! it's something simple yet hard to do! The following script allows you to count howmany times your article get's read and displays this on the article in a datatable, you can however NOT show the "times read" on your article but it sure is interesting for your visitors!
How does it work
It's simple. but not super-simple. you create a table holding an IP,DATE,PARENT_ID and if needed more information, like I did include a type. when the page loads you update the table using a sql query. my query checks if the IP did not request the same article in a time period of 10 minutes. this ensures that the visitor did not hit "back" on accident and eliminates valse countings. did you rly expect a script that just "updates". I like my statistics to be correct so I use this system it still isnt fool proof. but almost...
why should you use it?
- statistics for yourself.
- statistics for visitors ( they like it!)
adding soon
script that checks if anonymous proxy-server is found. if yes do not update at all.
the script!
just echo $viewdata['total'] to print the number of views.
ENJOY!
( I WROTE THIS CODE & TUTORIAL... please give credit to me if you post this somewhere else )
ah! counting visitors! it's something simple yet hard to do! The following script allows you to count howmany times your article get's read and displays this on the article in a datatable, you can however NOT show the "times read" on your article but it sure is interesting for your visitors!
How does it work
It's simple. but not super-simple. you create a table holding an IP,DATE,PARENT_ID and if needed more information, like I did include a type. when the page loads you update the table using a sql query. my query checks if the IP did not request the same article in a time period of 10 minutes. this ensures that the visitor did not hit "back" on accident and eliminates valse countings. did you rly expect a script that just "updates". I like my statistics to be correct so I use this system it still isnt fool proof. but almost...
why should you use it?
- statistics for yourself.
- statistics for visitors ( they like it!)
adding soon
script that checks if anonymous proxy-server is found. if yes do not update at all.
the script!
PHP:
// UPDATEN VAN DE VIEWS INDIEN DE BEZOEKER NIET DE LAATSTE 3 MINUTEN GELEDEN HET ARTIKEL BEZICHTICHT HEEFT
$newquery = "SELECT * FROM article_views WHERE date > (NOW()- INTERVAL 10 MINUTE) AND parent_id=$id AND ip='".$_SERVER['REMOTE_ADDR']."'";
$resultzz = mysql_query($newquery);
if (mysql_num_rows($resultzz) == 0)
{
mysql_query("INSERT INTO article_views (ip,date,parent_id,type) VALUES ('$_SERVER[REMOTE_ADDR]',now(),'$id','paid')");
}
// FETCHEN VAN VIEW-DATA
// --- FETCHEN VAN TOTAAL AANTAL KEER GELEZEN ---
$newquery = "SELECT COUNT(*) AS total FROM article_views WHERE parent_id=$id AND type='paid'";
$view_result = mysql_query($newquery);
$viewdata = mysql_fetch_assoc($view_result);
$views = $viewdata['total'];
just echo $viewdata['total'] to print the number of views.
ENJOY!
( I WROTE THIS CODE & TUTORIAL... please give credit to me if you post this somewhere else )