Useful PHP code – guestbook counter


You want to display a counter on your web page, but you do not want to use a db.



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;




$fh=fopen(“/tmp/counter.txt”, “r”);
$fh=fopen(“/tmp/counter.txt”, “w+”);
if(fputs($fh,($cnt+1))) { print(“You are visitor: $cntn”); }




[tags]PHP Guest Book, PHP Coding School[/tags]


If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *