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![]()

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"); ?>
XHTML, CSS, AJAX, JS, php, MySQL.
--
HxF moderators can't read timestamps.
[/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.Originally Posted by bondie.
i think it stores it in counter.txt so then it shows up i am not sure so dont count on it
counter.txt contains a number, when you include it, you only include a number, not other crap.
XHTML, CSS, AJAX, JS, php, MySQL.
--
HxF moderators can't read timestamps.
But, if it directs the code towards counter.php and the file is called counter.txt that would conflict the script?
No?Originally Posted by Cumec
But, if it directs the code towards counter.php and the file is called counter.txt that would conflict the script?
How do you think it would?
XHTML, CSS, AJAX, JS, php, MySQL.
--
HxF moderators can't read timestamps.
Ah, I getcha now. I forgot that part, and assumed it was obvious.Originally Posted by :.:Numark:.:
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"
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.
XHTML, CSS, AJAX, JS, php, MySQL.
--
HxF moderators can't read timestamps.
Want to hide these adverts? Register an account for free!