6. VTU WEB TECHNOLOGY LAB | READ NOW

 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


STEPS TO EXECUTE PHP PROGRAM

  1. Copy the php code given below
  2. Save it with .php file name extension
  3. Place the file in the htdocs of XAAMP
  4. Start the XAAMP control panel
  5. Start Apache server
  6. Click on admin in XAMPP Control pale
  7. Replace the url dashboard name with your php file name
  8. Execution completed
See also  6TH SEM CSE COMPUTER GRAPHICS LAB | ALL IN ONE

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

WEB TECHNOLOGY

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

Leave a Reply

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

WhatsApp Icon Join For Job Alerts