<?php 
	$filename = "counter.data";		// Name of the file that will store our data
 
	$fp = fopen($filename, "c+");		// Open file
 
	if (flock($fp, LOCK_EX)) {		// Request file lock
		$current = fread($fp, "10");	// Read ten bytes from file
		$new = $current + 1;		// Count the current pageview
		echo($new);			// Output the result
		ftruncate($fp, 0);		// Truncate file (empty it)
		fseek($fp, 0);			// Set pointer to start of file (write from start of file)
		fwrite($fp, "$new");		// Write new value to file
		flock($fp, LOCK_UN);		// Release file lock
	}
	fclose($fp);				// Close file
?>