(7/2/2008)
NEW: World News Central! Where all of the most interesting news can be found in one place, at any time!
(6/13/2008)
Now Announcing: The professional GutterStar.net RSS Service! The GutterStar.net RSS Service is a flexible, streamlined, and fully customizable RSS feed parsing service for personal and commercial websites.
(3/7/2008)
For you web developers... Ever wanted to run your own chat room from your site? Well, now you can, as many as you like, on as many pages of your site as you like! This really is a truly dynamic chat plugin for your website! Oh yes, and it's free of course...
So click here to check out the new GutterStar.net Dynamic Live Chat Plugin!
To find additional resources, enter the search terms: "hit counter"
Change Log:
V2.1: Fixed: All of the include statements for automatically created variable files have been modified to check whether the file exists before running, which was causing problems for PHP5 users when these conditional statements were missing. All's well now though.
V2.0: Fixed: Includes a large bug fix regarding the accurate counting of the days of the current month, which effects the tracking of users currently online.
Introduction
Is this PHP script really world famous? Sure it is! Why not?!
So now, the exciting part, what exactly does the hit counter script do? Actually it does quite a lot. Essentially, this script is a hit counter, which tracks the number of visitors to your website.
First it measures the total number of hits for all time. Then it measures the number of hits for that particular day. Also, it measures the number of users that are currently browsing your website at that particular moment.
In addition to these basic features, you have the option to keep a history log. This feature will save the hit statistics every day, after midnight, to the history log file on the server. The format for the history log file is this, each line represents one day's activity, and the line is delimited by camas. The first section records the date for which that line represents, the second section records the total number of hits for that day, and the third section records the maximum number of users browsing your site at the same time, including the exact time that the peak activity occurred! This is very useful if you wish to know the dates and times that your site is most popular.
If you enable the auto email notification feature, you can have the contents of the history log file emailed to you at the end of each month! This process will reset the history log, so you won't have to receive the same content along with the new content each time.
The cama delimited format of the history log file is perfect for importing directly into most database applications, so tracking your website statistics will be simple.
A couple of other unique features include...
This script can be run invisibly in the background, so your analytics tracking can be done without any additional user impact.
Also, though this is a PHP script, it is possible to use this script within standard HTML pages using JavaScript! That's right... This script merges PHP with JavaScript to directly pass the necessary variables from PHP to JavaScript variables within the current document object!
So what does this look like?
The following code is available within the "Sample.htm.php" file, which is included in the download.
To display each value within a PHP page using the available variables, the following method will work...
<?
include("./hit_counter.php");
echo "The current total number of hits to date is $total. Today, there have been $today visitors. There are currently $cTotal users currently online. The most users that were online at the same time today ($hDate), were $hTotal at $hTime. The most users that were ever online at the same time were $maxTotalOnline, on $maxTotalOnlineDate at $maxTotalOnlineTime.";
?>
Alternatively, to display each value within a standard HTML page using JavaScript variables, the following will work...
document.write('The current total number of hits to date is ' + total + '. Today, there have been ' + today + ' visitors. There are currently ' + cTotal + ' users currently online. The most users that were online at the same time today (' + hDate + '), were ' + hTotal + ' at ' + hTime + '. The most users that were ever online at the same time were ' + maxTotalOnline + ', on ' + maxTotalOnlineDate + ' at ' + maxTotalOnlineTime + '.');
</script>
Both methods above will print the hit counter statistics as follows...
The current total number of hits to date is 41877. Today, there have been 29 visitors. There are currently 3 users currently online. The most users that were online at the same time today (Friday July 4; 2008), were 8 at 3:58 AM. The most users that were ever online at the same time were 16, on Friday June 20; 2008 at 1:05 AM.
Notice that these hit counter statistics directly reflect those displayed at the top right of this page. You know, where the sparkly bits are...
To run the hit counter invisibly in the background, simply use the following procedure...
Simply follow the instructions contained within the file: "hit_counter_config.php". A copy of this file's content follows...
<?
/* Relative folder where the supporting hit_counter files are stored. Must not end with a slash. Examples include...
If the hit_counter files are stored in "domain.com/hit_counter", and the hit_counter script is being included within a page at "domain.com", the relative folder should be set to $relativeFolder = './hit_counter';
However, if the hit_counter files are being stored at "domain.com/hit_counter", and the hit_counter script is being included in a page at "domain.com/mySubFolder/directory", the relative folder should be set to $relativeFolder = '../../hit_counter';
The default balue '.' assumes that all of these files will be referenced from the same folder as the given web page, where the PHP statement '<? include("hit_counter.php"); ?>' is located. */
$relativeFolder = '.';
// Save log of hit count statistics? true or false
$logHistory = true;
/* Send email log statistics at the end of each month? The log will automatically be cleared after the message is sent. $logHistory must be set to true for this feature to work.
Enter the email address that you wish the log to be sent to. Example: 'example@domain.com'
Or leave this variable blank to automatically skip this feature. The log will not be cleared at the end of each month if left blank. */
$sendLogTo = '';
// The message displayed at the beginning of the log email.
$email_header = "Excelent! Your latest website statistics are ready! You lucky webmaster you...\n\n";
// The following date and time formats will be used when recording log statistics.
$historyDateString = 'l F j; Y';
$historyTimeString = 'g:i A';
/* The maximum time to detect when users are currently online. This number is reflected in the $cTotal variable, and refers to the number of users currently browsing your site at the moment. */
// The specified number of hours.
$time_hours = 0;
// The specified number of minutes.
$time_minutes = 10;
// The specified number of seconds.
$time_seconds = 0;
/* Okay... Now what?
1. After uploading all of these files, give the file named "hit_counter_history.txt" a permition of 766, to allow the file to be written to at runtime.
2. If all of these files are in the same folder as the page or pages that will include the hit_counter script, this file should be uploaded to the same folder.
However, if the hit_counter script is going to be included on a page within another folder, this file should be uploaded to the same folder as the page where the hit counter will be included. Hence the importance of the relative path variable at the top of this file. Also, this method will allow you to access the script from multiple pages within various folders across your website, to record site-wide traffic statistics.
3. Give this file, hit_counter_config.php, a permition of 600 to ensure security.
4. Use the examples contained within the file "Sample.htm.php" to learn how to implement this script on your web pages.
PHP
Paradigm
imperative,
object-oriented
Appeared in
1995
Designed by
Rasmus Lerdorf
Developer
The PHP Group
Latest release
5.2.5/
8 November
2007
Typing discipline
Dynamic, weak
Influenced by
C,
Perl,
Java,
C++,
Python
OS
Cross-platform
License
PHP License
Website
http://php.net/
table end
PHP is a computer
scripting language
originally designed for producing
dynamic web pages.
[1]
The name PHP is a
recursive acronym
for PHP: Hypertext Preprocessor.
PHP is used mainly in
server-side scripting
, but can be used from a
command line interface
or in standalone
graphical applications.
Textual User Interfaces
can also be created using
ncurses.
The main implementation is produced by The PHP Group and released under the
PHP License
. This implementation serves to define a
de facto
standard for PHP, as there is no
formal specification
. The most recent version of PHP is 5.2.5, released on
8 November
2007
. It is considered to be
free software
by the
Free Software Foundation.
[2]
PHP was written as a set of
Common Gateway Interface
(CGI) binaries in the
C programming language
by the Danish/Greenlandic programmer
Rasmus Lerdorf
in 1994, to replace a small set of
Perl
scripts he had been using to maintain his
personal homepage.
[3]
Lerdorf initially created PHP to display his
résumé
and to collect certain data, such as how much traffic his page was receiving. Personal Home Page Tools was publicly released on
8 June
1995
after Lerdorf combined it with his own Form Interpreter to create PHP/FI (this release is considered PHP version 2).
[4]
Zeev Suraski
and
Andi Gutmans
, two Israeli developers at the
Technion IIT
, rewrote the
parser
in 1997 and formed the base of PHP 3, changing the language's name to the
recursive initialism
PHP: Hypertext Preprocessor. The development team officially released PHP/FI 2 in November 1997 after months of
beta
testing. Public testing of PHP 3 began and the official launch came in June 1998. Suraski and Gutmans then started a
new rewrite
of PHP's core, producing the
Zend Engine
in 1999.
[5]
They also founded
Zend Technologies
in
Ramat Gan
, Israel, which actively manages the development of PHP.
In May 2000, PHP 4, powered by the Zend Engine 1.0, was released. The most recent update released by The PHP Group, is for the older PHP version 4 code
branch which, as of
January 2008
, is up to version 4.4.8. PHP 4 will be supported by security updates until
August 8,
2008.
[6]
On
July 13,
2004
, PHP 5 was released powered by the new Zend Engine II. PHP 5 included new features such as:
[7]
• Improved support for
object-oriented programming
• The PHP Data Objects extension, which defines a lightweight and consistent interface for accessing databases
• Performance enhancements
• Better support for
MySQL
and
MSSQL
• Embedded support for
SQLite
• Integrated
SOAP
support
• Data
iterators
• Error handling via
exceptions
Currently, PHP 5.x is the only stable version that is being actively developed; active development on PHP 4 ceased at the end of
2007
. However, critical security updates for PHP 4 will be provided until
August 8,
2008.
[8]
PHP 6 is currently under development, and is slated to release in conjunction with the decommission of PHP 4.[citation needed]
As a result of the GoPHP5 initiative, many high profile open source projects ceased to support PHP 4 in new code as of
5 February
2008.
[9]
PHP is a widely-used general-purpose scripting language that is especially suited for
Web development
and can be embedded into HTML. PHP generally runs on a
web server
, taking PHP code as its input and creating Web pages as output. However, it can also be used for
command-line
scripting and
client-side
GUI
applications. PHP can be deployed on most
web servers
and on almost every
operating system
and
platform
free of charge. The PHP Group also provides the complete source code for users to build, customize and extend for their own use.
PHP primarily acts as a
filter
. The PHP program takes input from a file or stream containing text and special PHP instructions and outputs another stream of data for display.
From PHP 4, the PHP parser
compiles
input to produce
bytecode
for processing by the
Zend Engine
, giving improved performance over its
interpreter
predecessor. PHP 5 uses the Zend Engine II.
Originally designed to create dynamic web pages, PHP's principal focus is
server-side scripting
. While running the PHP
parser
with a
web server
and
web browser
, the PHP model can be compared to other server-side scripting languages such as
Microsoft
's
ASP.NET
system,
Sun Microsystems' JavaServer Pages
, and
mod perl
as they all provide dynamic content to the
client
from a web server. To more directly compete with the "framework" approach taken by these systems, Zend is working on the
Zend Framework
- an emerging (as of June 2006) set of PHP building blocks and best practices; other
PHP frameworks
along the same lines include
CakePHP,
PRADO
and
Symfony.
The
LAMP
architecture has become popular in the Web industry as a way of deploying inexpensive, reliable, scalable, secure web applications. PHP is commonly used
as the P in this bundle alongside
Linux,
Apache
and
MySQL
, although the P can also refer to
Python
or
Perl
. PHP can be used with a large number of
relational database management systems
, runs on all of the most popular web servers and is available for many different
operating systems
. This flexibility means that PHP has a wide installation base across the Internet;
As of April 2007
, over 20 million Internet domains were hosted on servers with PHP installed.
[10]
The number of installations is different from the number of sites actually using those installations, but this statistic does reflect the popularity of
PHP.
Examples of popular open source server-side PHP applications include
phpBB,
WordPress
, and
MediaWiki.
PHP also provides a
command line interface
SAPI
for developing shell and desktop applications, daemons, log parsing, or other system administration tasks that have traditionally been the domain of
Perl,
Python,
awk
, or
shell scripting.
[11]
PHP provides bindings to
GUI
libraries such as
GTK+
(with
PHP-GTK),
Qt
with PHP-Qt and text mode libraries like
ncurses
in order to facilitate development of a broader range of
cross-platform
GUI applications.
As with many scripting languages, PHP scripts are normally kept as human-readable source code, even on production webservers. While this allows flexibility,
it can raise issues with security and performance.
Encoders hinder source code
reverse engineering
. Encoders fall broadly into two types; those that hide source code and those that compile code into "optcode."[citation needed]
The downside of this latter approach is that a special extension has to be installed on the server in order to run encoded scripts, however the approach
of encoding compiled code and use of an extension offers typically the best performance, security and opportunity for additional features that may be useful
for developers. Compiled code solutions may exploit the potential for increased security through the use of their own execution engine, although some simpler
solutions rely on the regular PHP engine to execute the compiled code. The most commonly used packages for source code protection are from
Zend Technologies
and
ionCube Ltd.
Code optimizers improve the quality of the compiled code by reducing its size and making changes that can reduce the execution time and improve performance.
The nature of the PHP
compiler
is such that there are often many opportunities for
code optimization.
Accelerators offer performance gains by
caching
the compiled form of a PHP script in
shared memory
to avoid the overhead of
parsing
and
compiling
the code every time the script runs. They may also perform
code optimization
to provide increased execution performance. Both commercial (e.g. Zend Platform) and open source accelerators (e.g. xcache, eAccelerator, APC) are available.
The
PHP Extension and Application Repository
(PEAR) project aims to provide reusable libraries and components for PHP development. PEAR projects are usually written in PHP code using the
Object-oriented programming
paradigm.
PHP has a formal development manual that is maintained by the
free software community
. In addition, answers to many questions can often be found by doing a simple internet search. PHP users assist each other through various media such as
chat, forums, newsgroups and PHP developer web sites. In turn, the PHP development team actively participates in such communities, garnering assistance
from them in their own development effort (PHP itself) and providing assistance to them as well. There are many help resources
[14]
available for the novice PHP programmer.