Jump to content

Hit Counter


forumnz

Recommended Posts

i would have 2 tables in a database

______________________________

|      Site        |        Hits          |

----------------------------------

then as you suggested have something like

ref.php?site=abcd

 

in ref just have a short script something like this

 

$site = $_GET["site"];
mysql_query("UPDATE ref SET Hits = Hits+1 WHERE Site="$site; ");
header('Location: ' . $site);

 

its a simple in place update hope that helps

Link to comment
https://forums.phpfreaks.com/topic/70961-hit-counter/#findComment-356827
Share on other sites

A nice file alternative is:

 

FOR PHP 5:

$site = $_GET["site"];
$hits = file_get_contents('.\\hits\\'.$site);
if (empty($hits)) {$hits=0;} $hits += 1;
file_put_contents('.\\hits\\'.$site,$hits);
header('Location: ' . $site);
exit();

 

FOR PHP 4:

$site = $_GET["site"];
$hit = fopen('.\\hits\\'.$site,'r');
$hits = fread($hit,64);
fclose($hit);
if (empty($hits)) {$hits=0;} $hits += 1;
fopen('.\\hits\\'.$site,'w');
fwrite($hits); fclose();
header('Location: ' . $site);
exit();

Link to comment
https://forums.phpfreaks.com/topic/70961-hit-counter/#findComment-356830
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.