Page accessed increment()); ?> times.

*/ //$_SERVER["DOCUMENT_ROOT"] = "/home/julien/public_html"; // ----------------------------------------------- // print a debug string (hidden in the browser) if (! function_exists("debug")) { function debug($debugString) { print("\n"); } } class Counter { var $counterFile = "scripts/count.txt"; var $newCounterFile = "scripts/count-new.txt"; function pathToRoot() { return getenv("DOCUMENT_ROOT") ."/"; } function extractCountForFile($aNameOfFile) { $linesOfFile = file($this->pathToRoot() . $this->counterFile); $index = 0; while(($index <= sizeof($linesOfFile))) { $indexOfSeparator = strpos($linesOfFile[$index], "$"); $nameOfFile = substr($linesOfFile[$index], 0, $indexOfSeparator); if ($nameOfFile == $aNameOfFile) { return substr($linesOfFile[$index], $indexOfSeparator+1, strlen($linesOfFile[$index])); } $index++; } return 0; } function value() { if ( $_GET['url'] == "" ) { return $this->extractCountForFile( getenv("REQUEST_URI") ); } else { return $this->extractCountForFile( $_GET['url'] ); } } function setNewValueForFile($aNameOfFile, $aValue) { $newFilePointer = fopen ($this->pathToRoot() .$this->newCounterFile , "w"); $index = 0; $saveIsDone = false; $linesOfFile = file($this->pathToRoot() . $this->counterFile); while(($index <= sizeof($linesOfFile))) { $indexOfSeparator = strpos($linesOfFile[$index], "$"); $nameOfFile = substr($linesOfFile[$index], 0, $indexOfSeparator); if ($nameOfFile == $aNameOfFile) { fwrite($newFilePointer , $aNameOfFile . "$" . $aValue . "\n"); $saveIsDone = true; // Sauvegarde faire - passer à la ligne suivante } else { fwrite($newFilePointer , $linesOfFile[$index]); } $index++; } if (! $saveIsDone) { fwrite($newFilePointer , $aNameOfFile . "$1\n"); } fclose($newFilePointer); unlink($this->pathToRoot() . $this->counterFile); copy($this->pathToRoot() . $this->newCounterFile, $this->pathToRoot() . $this->counterFile); //rename($this->pathToRoot() . $this->newCounterFile, $this->pathToRoot() . $this->counterFile); } function increment() { $newValue = $this->value() + 1; if ( $_GET['url'] == "" ) { $this->setNewValueForFile( getenv("REQUEST_URI") , $newValue); } else { $this->setNewValueForFile( $_GET['url'] , $newValue); } return $newValue; } // -------------------------------------------------- // statistics display function compute_statistics($aNameOfFile) { $linesOfFile = file($aNameOfFile); $index = 0; $allValues = array(); while(($index < sizeof($linesOfFile))) { $indexOfSeparator = strpos($linesOfFile[$index], "$"); if ($indexOfSeparator != -1) { $nameOfFile = substr($linesOfFile[$index], 0, $indexOfSeparator); $value = rtrim(substr($linesOfFile[$index], $indexOfSeparator+1, strlen($linesOfFile[$index]))); $allValues[$nameOfFile] = $value; } $index++; } return $allValues; } function display_statistics() { $statsArray = $this->compute_statistics($this->pathToRoot() . $this->counterFile); ksort($statsArray); print("\n"); print("\n"); $tr_odd = TRUE; $tr_class = "odd"; while (list ($key, $value) = each ($statsArray)) { if($tr_odd) { $tr_class = "odd"; }else { $tr_class = "even"; } print("\n"); $tr_odd = ! $tr_odd; } print("\n
PageCompte
".$key." ".$value."
"); } } $counter = new Counter; ?>