VB icon

counter

Email
Submitted on: 1/1/2015 5:01:00 AM
By: Gowin Down (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 1452
 
     Shows how to create a counter, as well as record the date and time into a file.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :counter
//**************************************
// I don't care what you do with this
// code, use it for whatever you want.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: counter
// Description:Shows how to create a counter, as well as record the date and time into a file.
// By: Gowin Down (from psc cd)
//
// Inputs:Two files are read to keep track of the hits, one called "count.txt" and another called "ip.txt". You may change these if you wish.
//
// Returns:It displays the amount of hits as well as the ip address of the user.
//
// Assumes:You must make sure that you create a blank textfile called count.txt before you run this script, otherwise it will give you errors the first time it runs, after the first run, it will be fine.
//**************************************

<?PHP
 // Place the location of files into variables
 $location_counter = "count.txt";
 $location_ip = "ip.txt";
 // Finds how many people have visited and adds one to it
 $counter = join('', file($location_counter));
 trim($counter);
 $counter++;
 // Print lines to the screen
 echo "<html><body><center><h1>COUNTER</h1>";
 echo "<p>You are visitor number: $counter</p>";
 echo "<p>Your IP address is: $REMOTE_ADDR</p>";
 echo "</center></body></html>";
 // Changes the value of the counter in the count.txt file
 $fp = fopen($location_counter,"w");
 fputs($fp, $counter);
 fclose($fp);
 // Adds one more ip address to the end of the ip.txt file
 $date = date("H:i:s d M, Y");
 $fp = fopen($location_ip,"a");
 fputs($fp, "Date: $date IP: $REMOTE_ADDR \n");
 fclose($fp);
?>


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


 There are no comments on this submission.
 

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.