JAVA N WEB TECH SYLLABUS

Thursday, December 23, 2010

Program to keep track of the number of visitors, visited the web page and display the counter with proper headings.

count.html
<html>
<body>
To know the no of times the web page Count.php is viewed <a href="http://192.168.8.3/naveen/count.php">Click Here</a>
</body>
</html>

count.php

<?

$filename = 'c.txt';

if (file_exists($filename))
    {
        $count = file('c.txt'); //read all the lines from the file c.txt and store it in array
        $count[0] ++;//increment the first line
        $fp = fopen("c.txt", "w"); //open c.txt in write mode
        fputs ($fp, "$count[0]"); //put the updated value in c.txt 
        fclose ($fp);
        echo "No of vistors vistin the pages is $count[0]";
    }
?>
Note:For this code u hav to create c.txt in u r webcontainer
go to u r web contain
cd /var/www/html/<usn>
vi c.txt
enter the value 0 and save it
change the permission of c.txt to 777
access the html to see the no of times the page is visited.

No comments:

Post a Comment