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 :)
Printable View
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 :)
Create a file called counter.php and put this code in it.
In the same directory make counter.txt and put a zero in it. (In *nix CHMOD the text file to 646)PHP Code:<?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);
}
?>
To include it in a php enabled page.
HTML Code:Hits: <?php include("counter.txt"); ?>
[/QUOTE]HTML Code:Hits: <?php include("counter.txt"); ?>
Although it would be counter.php otherwise the code wouldnt work ;)
i think it stores it in counter.txt so then it shows up i am not sure so dont count on it :)
Correct.Quote:
Originally Posted by bondie.
counter.txt contains a number, when you include it, you only include a number, not other crap.
But, if it directs the code towards counter.php and the file is called counter.txt that would conflict the script?
No?Quote:
Originally Posted by Cumec
How do you think it would?
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.Quote:
Originally Posted by :.:Numark:.:
PHP Code:<?php include("counter.php"); ?> // Anywhere on the page, to add to the counter.
<?php include("counter.txt"); ?> // Wherever you want the amount to show.