Important alert: (current site time 7/15/2013 10:39:32 AM EDT)
 

VB icon

A Simple Hit Counter

Email
Submitted on: 5/17/2003 1:46:03 PM
By: Jeff Cook/Moab Software  
Level: Beginner
User Rating: By 8 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 19000
author picture
(About the author)
 
     This is just a simple hits counter that will display the following: hits: 345 or whatever the file says chmod "counter.txt" to 0777 for this to work
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: A Simple Hit Counter
// Description:This is just a simple hits counter that will display the following:
hits: 345
or whatever the file says
chmod "counter.txt" to 0777 for this to work
// By: Jeff Cook/Moab Software
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1008&lngWId=8//for details.//**************************************

<?php
$file="counter.txt";
$handle=fopen($file, "r+");
$hits=fread($handle,filesize("$file"));
$hits+=1;
fclose($handle);
echo "$hits";
$handle=fopen($file, "w");
fwrite($handle, $hits);
fclose($handle);
 ?>


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
12/18/2003 8:55:25 PM

I just gotta say this script is excellent!
Its the most simple but yet effective and working counter ive seen. It only takes up what, 11 lines when other counters take up like 30-40 lines.

Excellent code! Thanks alot Jeff Cook.
(If this comment was disrespectful, please report it.)

 
12/20/2003 8:57:14 PMJeff Cook/Moab Software

thanks you for your comments
(If this comment was disrespectful, please report it.)

 
1/1/2004 10:30:54 PM

what do i put in a html doc for the hits to be displayed?
(If this comment was disrespectful, please report it.)

 
1/2/2004 11:09:45 PMJeff Cook/Moab Software

First of all, you need to have your web page in the *.php form, and your server needs to support php. If that is done you either paste in the exact code above, into your page code or save it as "counter.php" and put this in your page:

(If this comment was disrespectful, please report it.)

 
5/18/2004 3:53:47 PM

Have the counter.php in you directory and use in your html page only works if you have support for php.

Anyway nice code.
(If this comment was disrespectful, please report it.)

 
6/6/2005 3:55:33 AM

Very cool code, I've only just started learning php and this is quite helpful. :)

How about a tutorial on how this works next? ;)
(If this comment was disrespectful, please report it.)

 
7/16/2005 12:01:08 AMSteve Bailey

this helped me through the first rough bits, so thanks m8! 5/5
(If this comment was disrespectful, please report it.)

 
9/1/2005 10:49:50 AMHiginio

how can I know how many visitors there are just right now in any page?
please escuse my english
(If this comment was disrespectful, please report it.)

 
3/19/2007 5:13:38 PMChiroz

Does what it say...
Great for newbies...
Nothing special anout it ^^ 4 globes
(If this comment was disrespectful, please report it.)

 
9/4/2007 3:11:32 PMAric Holland

Good Code, i like the input and output code , from a remote text file...

Will most likely, build a comments form using your input & output PHP Code :P

Thanks...
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.