VTU WEB TECHNOLOGY LAB
6] WRITE A PHP PROGRAM TO KEEP TRACK OF THE NUMBER OF VISITORS VISITING THE WEB PAGE AND TO DISPLAY THIS COUNT OF VISITORS, WITH PROPER HEADINGS
Table of Contents
STEPS TO EXECUTE PHP PROGRAM
- Copy the php code given below
- Save it with .php file name extension
- Place the file in the htdocs of XAAMP
- Start the XAAMP control panel
- Start Apache server
- Click on admin in XAMPP Control pale
- Replace the url dashboard name with your php file name
- Execution completed
Solution 1 – prog6.php
<?php echo "<h1> REFRESH PAGE </h1>" ; $file = 'count.txt' ; $c = file_get_contents($file) ; file_put_contents($file, $c+1); echo "The number of users visited : ".$c ; ?>
WEB TECHNOLOGY – Output

Solution – 2 prog6.php
<?php print "<h3> REFRESH PAGE </h3>"; $name="counter.txt"; $file = fopen($name,"r"); $hits= fscanf($file,"%d"); fclose($file); $hits[0]++; $file = fopen($name,"w"); fprintf($file,"%d",$hits[0]); fclose($file); print "Total number of views: ".$hits[0]; ?>
WEB TECHNOLOGY Output
REFRESH PAGE
Total number of Views : 5