[problem]
You want to display a counter on your web page, but you do not want to use a db.
[/problem]
[solution]
All you need to make this work is echo “1” into a file called counter and ensure the web user has write access. For example: $ echo 1 > counter; chmod 777 counter;
[/solution]
[example]
<?php
$fh=fopen(“/tmp/counter.txt”, “r”);
$cnt=fread($fh,filesize(“/tmp/counter.txt”));
fclose($fh);
$fh=fopen(“/tmp/counter.txt”, “w+”);
if(fputs($fh,($cnt+1))) { print(“You are visitor: $cntn”); }
fclose($fh);
?>
[/example]
[reference]
[tags]PHP Guest Book, PHP Coding School[/tags]
- PHP Docs fopen Function
- PHP Docs fputs Function
- PHP Docs fread Function
- PHP Docs fclose Function
- PHP Docs filesize Function
[/reference]