Post Reply  Post Thread 
Simple php script for site visitor counter
Author Message
admin
~CM~
*******


Posts: 147
Group: Administrators
Joined: Jul 2007
Status: Offline
Reputation: 0
Thank 0
1 was given thank in 1 posts
Post: #1
Simple php script for site visitor counter

Following is a simple way to log number of visitors to your site, there is no need of any database, it uses flat files (plain textfiles) only.

Create an empty file named sitestats.txt.

Create a php file, call it sitecounter.php or something, and put it in the same directory as the sitestats.txt file.

Following is PHP code:

PHP Code:
<?php
$counter_file 
= (“sitestats.txt”);
$visits file($counter_file);
$visits[0]++;
$fp fopen($counter_file “w”);
fputs($fp “$visits[0]);
fclose($fp);
echo 
“Site Visitors$visits[0];
?>


Following is the explaination of PHP script

1. Define the textfile with stats
2. Read the stats from the file
3. increase the stats with 1
4. open the stats file in writing mode
5. write to the file
6. close the file
7. and finally, print out the content


Thanks & Regards
------------------
~CM~

ADD TO DEL.ICIO.US  ADD TO DIGG  ADD TO FURL  ADD TO NEWSVINE  ADD TO NETSCAPE 
ADD TO TECHNORATI FAVORITES  Technorati ADD TO SQUIDOO  ADD TO WINDOWS LIVE  ADD TO YAHOO MYWEB  ADD TO ASK 
ADD TO REDDIT  ADD TO STUMBLEUPON  ADD TO GOOGLE   

This post was last modified: 07-18-2007 07:20 PM by admin.

07-18-2007 07:19 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  PHP Script to parse /etc/passwd and how to use the new __get magic method (PHP5) admin 0 424 07-19-2007 03:46 PM
Last Post: admin
  PHP script to find difference between server time and local time admin 0 435 07-18-2007 04:36 AM
Last Post: admin
  GD test script Nilesh 0 625 07-15-2007 09:31 AM
Last Post: Nilesh
  Zend Optimizer test script Nilesh 0 1,039 07-15-2007 09:22 AM
Last Post: Nilesh
  How to Send Email from a PHP Script Using SMTP Authentication Nilesh 0 3,485 07-15-2007 09:17 AM
Last Post: Nilesh
  PHP script for backup of mysql database admin 0 521 07-15-2007 03:33 AM
Last Post: admin
  PHP script for Duration Calculator admin 0 304 07-15-2007 03:23 AM
Last Post: admin

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: