Unique Visitor Counter in PHP

Congratulations! You are lucky visitor number... 1!!!

1 unique visitors

246 pageviews

Similar to the PHP Pageview Counter, this will display the number of unique visitors to your site, styled however you like.

Set a cookie in PHP or JavaScript so that the same visitor isn't counted twice until a designated amount of time.

This script includes the same extra features listed on the PHP Pageview Counter page.

Source Code

PHP

$visitor_txt = 'visitors.txt';

$dat = file_get_contents($visitor_txt);
if (!isset($_COOKIE[$cookie_name])) {
if ($dat !== false)
{
$fil = fopen($visitor_txt, "w");
if (flock($fil, LOCK_EX)) {
echo '',number_format($dat2+1),' unique visitors';
fwrite($fil, $dat+1);
flock($fil, LOCK_UN);
}
fclose($fil);
}
}

else {
echo '',number_format($dat+0),' unique visitors';
}