|
|
|
| Title : |
Smart Counter - This little script is a plain and simple hit counter that uses cookies to determine whether or not the visitor has already been counted. |
| Categories : |
Cookies, HTML and PHP, PHP |
 Jason Hines |
| Date : |
Jul 19th 1999 |
| Grade : |
4 of 5 (graded 1 times) |
| Viewed : |
11381 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Jason Hines |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<?php
/*
Orig: simple access counter for php3
(c)1998 David W. Bettis
dbettis@eyeintegrated.com
Modified smart counter:
Uses cookies to determine whether or not to bump the
count. Cookie expires after 10 minutes.
v1.1 Jason Hines <openface@eyeintegrated.com>
*/
$counterFile = "/home/httpd/html/counter/counter.text";
function displayCounter($counterFile) {
global $counted
$fp = fopen($counterFile,rw);
$num = fgets($fp,5);
if (!$counted) {
$num += 1;
unlink("$counterFile");
exec("echo $num > $counterFile");
}
print "$num";
}
if (!file_exists($counterFile)) {
exec("echo 1 > $counterFile");
}
displayCounter($counterFile);
?>
/* Add the following to the very top of the page you want to count */
<?php if (!$counted) { setcookie("counted",1,time()+600); } ?>
|
|
| Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with
PHP 4.2.0 Categories : PHP, HTML and PHP, Global Variables, Cookies, Variables | | | Function that allows a Javascript cookie to be set after HTML has been outputted to the page.
Categories : PHP, Java Script, Cookies, HTML and PHP | | | Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database. Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | Parse string to find sub-string between two arbitrary strings Categories : PHP, Strings, HTML and PHP, Arrays | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | Database resultset navigation Categories : PHP, HTML and PHP, Databases, MySQL, Navigation | | | webcam cam view image ispy browser independant Categories : Graphics, HTML, HTML and PHP, PHP | | | Function to do live population of HTML's <Select> tag from a Table Categories : PHP, MySQL, HTML and PHP, Databases | | | Customizable encoding and decoding strings with security. Categories : PHP, Strings, HTML and PHP | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | Sed, a coder's best friend. This lovely linux command allows you to swap strings in a file. Great for changing a variable name in a script with
multiple files. Categories : HTML and PHP, HTML and PHP | | | Record Set Paging with PHP (RSP) Categories : PHP, MySQL, Navigation, Databases, HTML and PHP | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | This program will take data from a user via a web based form, validate it, show it
to the user for re-validation, and finally insert it into the database. Plenty of
sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases | |
| | | | Rudi Ahlers wrote : 548
Can someone please help me with this script. I get nerror: Parse error: parse error, expecting ``,`` or ``;`` in /home/www/projects/header.php on line 21 which is:
$fp = fopen($counterFile,rw);
I do have the file counter.txt, as -rw-rw-rw
But it doesn`t seem to read the file, I even included the whole path to the file. Can someone please tell me why?
| | | | xtentic xtentic wrote :734
function displayCounter($counterFile) {
global $counted;
$fp = fopen($counterFile,rw);
$num = fgets($fp,5);
if (!$counted) {
$num += 1;
unlink("$counterFile");
exec("echo $num > $counterFile");
}
print "$num";
}
^^^^ This works! 4 real
| |
|
|