<!DOCTYPE HTML> <html> <!-- here there is a php code executed by the server, client receive only the output --> <?php // We use a file to store the counter // THE FOLLOWING CODE IS NOT SAFE! Multiple instance of the web server can // conflict on writing file; we use this code only for educational purposes. // $file='/tmp/countx.txt'; //read counter if(file_exists($file)) { $handle = fopen($file, "r"); $x=(int)fread($handle,100); fclose($handle); }else{ $x=0; } //increase counter $x=$x+1; //write back the counter $handle = fopen($file, "w"); fwrite($handle,"".$x); fclose($handle); ?> <!-- end of the php code --> <body> Visit Count: <!-- here there is a php code executed by the server, client receive only the output --> <?php //out the counter echo $x; ?> <!-- end of php code --> <br /><i>Watch the client-side HTML code and compare with the <a href="visit_count_code.php">server-side code</a></i> </body> </html>