note 92569 added to function.file-put-contents
| From: | JohnGalt at osu1 dot php dot net | Date: | Wed, 29 Jul 2009 19:14:08 +0000 |
| Subject: | note 92569 added to function.file-put-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158890@lists.php.net to get a copy of this message | ||
I use file_put_contents() as a method of very simple hit counters. These are two different examples
of extremely simple hit counters, put on one line of code, each.
Keep in mind that they're not all that efficient. You must have a file called counter.txt with
the initial value of 0.
For a text hit counter:
<?php
$counter = file_get_contents("counter.txt"); $counter++;
file_put_contents("counter.txt", $counter); echo $counter;
?>
Or a graphic hit counter:
<?php
$counter = file_get_contents("counter.txt"); $counter++;
file_put_contents("counter.txt", $counter); for($i = 0; $i < strlen($counter); $i++)
echo "<img src=\"counter/".substr($counter, $i, 1).".gif\"
alt=\"".substr($counter, $i, 1)."\" />";
?>
----
Server IP: 69.147.83.197
Probable Submitter: 72.208.240.199
----
Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php
Edit -- https://master.php.net/note/edit/92569
Del: integrated -- https://master.php.net/note/delete/92569/integrated
Del: useless -- https://master.php.net/note/delete/92569/useless
Del: bad code -- https://master.php.net/note/delete/92569/bad+code
Del: spam -- https://master.php.net/note/delete/92569/spam
Del: non-english -- https://master.php.net/note/delete/92569/non-english
Del: in docs -- https://master.php.net/note/delete/92569/in+docs
Del: other reasons-- https://master.php.net/note/delete/92569
Reject -- https://master.php.net/note/reject/92569
Search -- https://master.php.net/manage/user-notes.php