WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
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 Update Picture
Jason Hines
Date : Jul 19th 1999
Grade : 4 of 5 (graded 1 times)
Viewed : 9533
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

  Submit your own code examples 
 

<?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); } ?>



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
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
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
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
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
phpCards - PHP/mySQL postcard script with web based admin to add, edit, and delete cards and categories. Very easy to install.
Categories : PHP, Complete Programs, HTML and PHP, MySQL
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions
html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP
PageRank Display
Categories : Search Engines, HTML and PHP, PHP
PHP, simple, counter, bala
Categories : HTML and PHP, PHP, PHP Options and Info
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
Dynamic Calender in PHP, Javascript and HTML.
Categories : PHP, Java Script, HTML and PHP, Calendar
 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 &gt; $counterFile"); 
        } 
        print "$num"; 



^^^^ This works! 4 real