[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
PHPAdvanceCode
--------------------------------------------------
This tutorial covers advanced issues of PHP programming. It assumes that you know at least how to deal with files in PHP.
One of the easiest things to do with PHP is, writing a counter for your homepage.
This script is rather straightforward. We store the counter variable in a file, "guestbook.txt" and increase the variable each time the site is updated or loaded again. The HTML part needs no further explanation. We simply print the value of the $counter variable on the screen. Thats it.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
PHPAdvanceCode
Advanced PHP Programming
--------------------------------------------------This tutorial covers advanced issues of PHP programming. It assumes that you know at least how to deal with files in PHP.
Writing a Counter for your Homepage
One of the easiest things to do with PHP is, writing a counter for your homepage. //the filename for storing the counter $filename = "guestbook.txt"; //our counter variable $counter = 0; //checking if the file exists. if so, write the counter into it if(file_exists($filename)) { $file = fopen($filename,"r"); if($file) { $counter = fgets($file,255); fclose($file); } } //the page has been updated, so increase the counter $counter++; $file = fopen($filename,"w"); if($file) { fputs($filename,"w"); fclose($file); } //Here comes the HTML part <html> <head><title></title></head> <body> <? echo "You are visitor number: $counter on this page"; ?> </body> </html>
This script is rather straightforward. We store the counter variable in a file, "guestbook.txt" and increase the variable each time the site is updated or loaded again. The HTML part needs no further explanation. We simply print the value of the $counter variable on the screen. Thats it.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
