Jump to content
xisto Community
Sign in to follow this  
matak

<?php ?> Unique Visitors Script Flat file unique visitors script (no sessions)

Recommended Posts

This is really simple script. Well at least this part is, but it could be extendable. Only problem is that it's not really for massive websites with hundread of visitors a day, but rather for small ones. But it is a good script to figure out how to make a visitor counter script.

Anyway here's the snippet.

<?phpfunction getVisits($variable) {	$visits = array();	if ($handle = opendir('stats/')) {	while (false !== ($file = readdir($handle))) {		if ($file != "." && $file != "..") {			array_push($visits, $file);		}	}	closedir($handle);	}	$key = array_search($variable, $visits);		if ($key !== FALSE) {				echo "Posjeta do sada: ".count($visits);			}	elseif ($key === FALSE){		$file = fopen("stats/".$variable, 'a');		fwrite($file, $variable);		fclose($file);			getVisits($variable);	}}?>

Just call it with getVisits($_SERVER['REMOTE_ADDR'])., and be sure to have that stats directory in same root as file in which script is executed.

Comments or improvments are welcome.

Share this post


Link to post
Share on other sites

Ok, fast reply works again :PYeah, mySQL is great, this is like i stated for small sites with less than 10(0) visitors a day :P. I'm extending the script so it saves in directories based on a date value, and stuff like that, so that later i don't have like millions of files. :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.