OfficeTrio: The Integrated ECommerce Solution OfficeTrio: The Integrated ECommerce Solution OfficeTrio: Features OfficeTrio: User Manual OfficeTrio: Testimonials OfficeTrio: The Demo is Offline! OfficeTrio: Order O3 Now

Perl Hit Counter Script Explanation

Line By Line...
hits.pl

This script is a basic page hits counter. It stores the hit count in a database table called 'hits'...

  • The first line tells Unix this is a Perl program. The second is a comment describing the script.
     #!/usr/local/bin/Perl
     # hits.pl - V1.0 - TGH 26 May 2001


  • This makes the DBI (DataBase Interface) library of functions available.
     use DBI;

  • Connect to the database.
     $dbh = DBI->connect("DBI:mysql:yourname:localhost:3306", 'yourname', 'password');

  • Create the SQL that will increment the counter for the page. The special variable '$_[0]' is the first parameter that was passed to the script - in this case the web page name.
     $statement = "update hits set counter = counter + 1 where page = $_[0]";
     $sth = $dbh->prepare($statement) or print "Can't prepare the SQL\n";


  • This runs the SQL on the database. the variable $rv contains the number of rows inserted!
     $rv = $sth->execute or print "Can't execute the query: $sth->errstr";
     print $rv, " rows inserted\n";


  • Close the 'statement handle' and disconnect from the database.
     $sth->finish;
     $dbh->disconnect;



To download any script, please go to the Free Scripts page.


Tutorials

Contents

Free EBooks
Free Scripts

Introduction
What Can I Do With A Website?
Internet History
Introduction
Preparation
Website Builders

Webmaster's Tools
Tools Intro
HTML Editor
PHP IDEs
Graphics Resources
Telnet and FTP
Miscellaneous Tools

Web Design
Web Design
Domains
Keywords/Description
Logo/Graphics

Creating Web Pages
Setup
HTML
HTML Tips And Tricks
Home Page
Navigation
Other Pages

Webhosting and Unix
Webhosting
Telnet/Unix
More Unix
Website Upload
Analyse And Verify

Programming
Programming 1
Programming 2

PHP
PHP
PHP Scripts
PHP Hit Counter Script
PHP Download Tracking Script
PHP Navigation Script
PHP Affiliates Tracking Script
PHP Users Management
PHP Site Search Script

Perl
Perl
Perl Hit Counter Script
Perl Order Processing Script

Databases
Databases
SQL
Database Setup

ECommerce
ECommerce

Automation
Automating Order Processing
PayPal Automation
Email Automation
Installing Scripts

Security
Basic Security

Affiliates
Affiliates Programs

Managing Your Website
Website Management
Promotion/Advertising
Search Engines
Search Engine Optimisation



Powered By OfficeTrio