View Full Version : I need a code for a text based hit counter..
GR4NT
06-06-2006, 11:45 PM
I need a hit counter, but not an image, a regular text one. This may make me sound nooby, but I'm not exactly your every day HTML coder.
Oh btw, this code can be in HTML or PHP :)
Heinous
08-06-2006, 07:52 AM
Create a file called counter.php and put this code in it.
<?php
$file = "counter.txt"; //URL of a text file to store the hits.
$open = fopen($file, "r");
$size = filesize($file);
$count = fread($open, $size);
fclose($open);
if (!isset($_COOKIE['simplecount'])) {
$open = fopen($file, "w");
$count++;
fwrite($open, $count);
fclose($open);
setcookie("simplecount","Counted!",time()+66600000);
}
?>
In the same directory make counter.txt and put a zero in it. (In *nix CHMOD the text file to 646)
To include it in a php enabled page.
Hits: <?php include("counter.txt"); ?>
Flauvo
08-06-2006, 05:20 PM
Hits: <?php include("counter.txt"); ?>[/QUOTE]
Although it would be counter.php otherwise the code wouldnt work ;)
Jamie.
08-06-2006, 07:42 PM
i think it stores it in counter.txt so then it shows up i am not sure so dont count on it :)
Heinous
09-06-2006, 12:34 AM
i think it stores it in counter.txt so then it shows up i am not sure so dont count on it :)
Correct.
counter.txt contains a number, when you include it, you only include a number, not other crap.
Flauvo
09-06-2006, 05:38 PM
But, if it directs the code towards counter.php and the file is called counter.txt that would conflict the script?
Heinous
10-06-2006, 04:01 AM
But, if it directs the code towards counter.php and the file is called counter.txt that would conflict the script?
No?
How do you think it would?
Recursion
10-06-2006, 06:13 AM
If they arent visisting counter.php then how will the Script know to add a number to the .txt file?
JUst goto Thybag.co.uk - They have one wich works and is easy to follow lol while we get on with this "Discussion"
Heinous
10-06-2006, 07:27 AM
If they arent visisting counter.php then how will the Script know to add a number to the .txt file?
JUst goto Thybag.co.uk - They have one wich works and is easy to follow lol while we get on with this "Discussion"
Ah, I getcha now. I forgot that part, and assumed it was obvious.
<?php include("counter.php"); ?> // Anywhere on the page, to add to the counter.
<?php include("counter.txt"); ?> // Wherever you want the amount to show.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2026 vBulletin Solutions Inc. All rights reserved.