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 : A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides Click here to Update Your Picture
leaping langoor
Date : Jun 07th 2004
Grade : 2 of 5 (graded 20 times)
Viewed : 13470
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

OK guys, this script is a simple file based counter. This is meant for sites that do not run a db and instead, use a file and a cookie. It isn't the best I've seen but it's simple. Consider this as a tutorial. :)

Just create a file called counter.txt and put this where you want to display the counter.
Remember to set the permissions on counter.txt so that your webserver can write to the file.

<?php
$visitor_ip
= $HTTP_COOKIE_VARS["user_ip"];
$counter = "counter.txt";
$counter_file_line = file($counter);

if(!
$visitor_ip)
{
 
setcookie("user_ip", $REMOTE_ADDR, time()+360000);
 
$counter_file_line[0]++;
 
$cf = fopen($counter, "w+");
 
fputs($cf, "$counter_file_line[0]");
 
fclose($cf);
}
elseif(
$visitor_ip != $REMOTE_ADDR)
{
 
$counter_file_line[0]++;
 
$cf = fopen($counter, "w+");
 
fputs($cf, "$counter_file_line[0]");
 
fclose($cf);
}
?>



Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
Simple Cookie example
Categories : PHP, Beginner Guides, Cookies
Simple image counter
Categories : PHP, Graphics, Filesystem, Beginner Guides
Store, retrieve and delete cookies using JavaScript.
Categories : Java Script, Cookies, Beginner Guides, Cookies
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL
News management class
Categories : PHP, PHP Classes, Beginner Guides
Authentication script to authenticate users in Active Directory through LDAP.
Categories : LDAP, Authentication, Cookies, PHP
php jump urls...the best way
Categories : PHP, URLs, Filesystem
Simple way to replace a variable value in a .conf (.ini) file using a webbrowser - the first stage of a complete universal configuration editor
Categories : PHP, Regexps, Code Editors, Filesystem