PHP Counter (PHPC)

The simplest web application that we will discuss is the technique of creating a counter using PHP. The counter that we create is to count how many times a website page has been displayed. To simplify it, the counter is displayed in text form, not graphically.

Algorithm: 

  1. When a web page is displayed, the contents of a particular file are first read and its values ​​are read.
  2. Display the value on the browser screen
  3. Increase the value by 1
  4. Save the new value in the file
  5. Finished.

Counter.txt file

0

Counter.php file

<?
$filecounter="counter.txt";
$fl=fopen($filecounter,"r+");
$hit=fread($fl,filesize($filecounter));

echo("<table width=250 align=center border=1 cellspacing=0 cellpadding=0 bordercolor=#0000FF><tr>");
echo("<td width=250 valign=middle align=center>"); echo("<font face=verdana size=2 color=#FF0000><b>"); echo("Anda pengunjung yang ke:"); echo($hit); echo("</b></font>"); echo("</td>"); echo("</tr></table>");
fclose($fl);

$fl=fopen($filecounter,"w+");
$hit=$hit+1; fwrite($fl,$hit,strlen($hit)); fclose($fl);
?>


Post a Comment

Previous Next

نموذج الاتصال