WarpConduit Computing

  • Quick Tips
  • Web Design & Development
  • Graphic Design
  • Home
  • WordPress Plugins
  • Password Generator
  • About
  • Contact

Simple Standalone PHP Web Counter

December 3, 2009 by Josh Hartman

In my search for a simple PHP web counter it was difficult to find one that wasn’t somehow connected to an external host and didn’t write IP addresses to a file and then use resources to search the file later.  With all the NAT firewalls out there counting visitors based on IP address just doesn’t seem like a modern thing to do. I took a script by Eric Sizemore and modified it to create my own version.  What it does is add to the visitor count (stored in a txt file on the server) if they don’t have a cookie showing that they have visited before, then i set that cookie to expire after 60 days, after that if the visitor comes again they will be counted again.  It’s not the most accurate, but gives a good idea of how many people are visiting and i wanted to reduce server file operations.

The Code

  Simple Standalone PHP Web Counter (9.6 KiB, 894 hits)

Installation & Usage

  1. Unzip the code into your website’s root folder
  2. Change permissions on the counter log txt file so that it is writable (chmod 666).
  3. Add the following PHP code at the top of each root page you would like to display the counter on:
    <?php include('counter/counter.php'); ?>

    <?php include('counter/counter.php'); ?>

  4. Add the following PHP code where you want to have the counter display:
    <?php show_counter(); ?>

    <?php show_counter(); ?>

  5. Test the page you’ve included counter.php on and have show_counter() displayed.

Filed Under: Web Design & Development Tagged With: counter, php

Connect

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • YouTube

Recent Posts

  • Extremely Useful Applications for Web Development and IT Tasks
  • Installing BookStack Wiki on cPanel Shared Hosting
  • Media (MIME) Type Reference List

Tags

automatic base64 benchmark cache counter css deflate email font gzip htaccess html image inarray increment inline images in_array javascript jquery link list magento mailto menu metadot mysql number obfuscation opencart operating system order php random redirect rewriterule slashes software timestamp ubuntu unix upgrade url windows windows 7 wordpress

Blogroll

  • CodeIgniter
  • Fusion Forward
  • jQuery
  • Nettuts+
  • Smashing Magazine

© 2022 WarpConduit Computing. All Rights Reserved.