Webmaster Forum  

Go Back   Webmaster Forum > Website Design Forum > Website Design Forum
User Name
Password
Register FAQ Members List Calendar Transactions Store Search Today's Posts Mark Forums Read


Simple Text Counter

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-05-2005, 13:19
italks
Member


Join Date: Oct 2005
Posts: 51
Trader Rating: (0)
Points: 0 (Donate)
5 F$/Referral Refer Friends
italks is on a distinguished road
Default Simple Text Counter

A common feature on most websites is a counter to show how many visitors have been to your site. This is our first example to show how to achieve this .
This example is very basic and far from ideal if you want an accurate count of your visitors because if you press refresh your counter will always increment by 1. This example does show some useful techniques such as opening and closing files.

Lets go through the process one step at a time . Firstly you have to create a simple text file and enter the number you wish the counter to start at , note this does not have to be 1 it can be any number you wish.
The next task will be to upload this to your server , if you have a Unix server this is where you have to watch because you have to set the permissions for your text file so the script can read and write to the file .
To change this you CHMOD your text file to 755. Refer to the help file or documentation of your FTP program to see how to achieve this.

Now for the script , call this something like counter.php
PHP Code:
<?php 
//this is our text file if you create a different named file change the script below to reflect this 
$counter_file = ("counter.txt"); 
//now we open the file 
$visits file($counter_file); 
//this increments the counter value by 1 
$visits[0]++; 
//now we will open the counter file for writing "w" 
$fp fopen($counter_file "w"); 
//put the new count value into the counter file 
fputs($fp "$visits[0]"); 
//close the file 
fclose($fp); 
//display the count 
echo "There have been $visits[0] visitors so far"
?>

Now add the following to your page where you wish the counter to appear
PHP Code:
<?php include("counter.php"); ?>

And that's it. You now have a working counter ready to be used!
italks is offline
Reply With Quote
  #2  
Old 10-23-2005, 23:12
Positive
Senior Member

Positive's Avatar

Join Date: Mar 2005
Posts: 2,565
Trader Rating: (4)
Points: 15 (Donate)
5 F$/Referral Refer Friends
Positive is on a distinguished road
Default Re: Simple Text Counter

I started a thread to find something similar yesterday. I didn't see this thread earlier. Thats what I was looking for thanks bunches.
Positive is offline
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Resources : | Advertise at FHF | itextLink.com| Reseller Hosting| TextDot| iNamePros| Any Webmaster| Web Host| Dep3| cheap low cost web hosting reviews|


All times are GMT -4. The time now is 01:52.


Powered by: vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.