Web Development Information
';

echo '

';

echo '

';

echo '

';

echo '

';

echo '

';

echo '

';

}

echo '';

You can also use custom functions to filter out search engines and crawlers. Or create graphs using PHP/SWF Charts (http://www.maani.us/charts/index.php). The possibilities are endless, and you can do all kinds of things!

In Conclusion...

In this article I have shown you have to create a logging module for your own PHP website, using nothing more than PHP and its built-in functions. To view the log file you need to parse it using PHP, and then display it in whatever way you like. It is up to you to create a kick-ass traffic analyzer.

If you still prefer to use a pre-built traffic analyzer, have a look at http://www.hotscripts.com.

About The Author

Dennis Pallett is a young tech writer, with much experience in ASP, PHP and other web technologies. He enjoys writing, and has written several articles and tutorials. To find more of his work, look at his websites at http://www.phpit.net, http://www.aspit.net and http://www.ezfaqs.com.


MORE RESOURCES:
Help with Tax Calculator - SitePoint
Help with Tax Calculator  SitePoint

StackBlitz achieves $4M ARR in 4 weeks with Claude AI web development platform - Anthropic
StackBlitz achieves $4M ARR in 4 weeks with Claude AI web development platform  Anthropic

10 of the best web development courses you can take online for free - Mashable
10 of the best web development courses you can take online for free  Mashable

Use These 15 Top Web Development Tools For Ecommerce Sites (2024) - Shopify
Use These 15 Top Web Development Tools For Ecommerce Sites (2024)  Shopify

100 Best Programming Languages in 2025 [Ultimate List] - Simplilearn
100 Best Programming Languages in 2025 [Ultimate List]  Simplilearn

AI and Web Development: Benefits and Limitations - devmio
AI and Web Development: Benefits and Limitations  devmio

Best Online Web Development Bootcamps Of 2024 - Forbes
Best Online Web Development Bootcamps Of 2024  Forbes

WordPress Web Hosting Services Market Size and Forecast Size, - openPR
WordPress Web Hosting Services Market Size and Forecast Size,  openPR

Best website builder service of 2024: The top 13 compared - TechRadar
Best website builder service of 2024: The top 13 compared  TechRadar

UA Little Rock Student Gains International Experience as Web Development Intern in Australia - University of Arkansas at Little Rock
UA Little Rock Student Gains International Experience as Web Development Intern in Australia  University of Arkansas at Little Rock

Innovation Series Edition 17: Web 3.0 for Sport for Development with Lucy Mills - sportanddev.org
Innovation Series Edition 17: Web 3.0 for Sport for Development with Lucy Mills  sportanddev.org

Top 10 Web Development Podcasts for Beginners You Need in Your Ears - Netguru
Top 10 Web Development Podcasts for Beginners You Need in Your Ears  Netguru

SEO and Web Design: How to Build a Website That Ranks (2025) - Shopify
SEO and Web Design: How to Build a Website That Ranks (2025)  Shopify

The best language for Android programming - SitePoint
The best language for Android programming  SitePoint

Ai Driven Web Scraping Market to Surge at 19.93% CAGR Through 2032 - openPR
Ai Driven Web Scraping Market to Surge at 19.93% CAGR Through 2032  openPR

Best Web Design Companies Of 2024 - Forbes
Best Web Design Companies Of 2024  Forbes

Help with database design for personal project - SitePoint
Help with database design for personal project  SitePoint

What's New in Laravel: Key Web App Development Trends to Watch in 2025 - openPR
What's New in Laravel: Key Web App Development Trends to Watch in 2025  openPR

Selling Behavior of Website Design Companies? - SitePoint
Selling Behavior of Website Design Companies?  SitePoint

Welcome animation conflict with barba js - SitePoint
Welcome animation conflict with barba js  SitePoint

A question for freelancers: productivity - General Web Dev - SitePoint
A question for freelancers: productivity - General Web Dev  SitePoint

The Best Web Design Software Of 2024 - Forbes
The Best Web Design Software Of 2024  Forbes

Web Design and Development - Muskegon Community College
Web Design and Development  Muskegon Community College

Button Styles Not Working On Phones - SitePoint
Button Styles Not Working On Phones  SitePoint

web development with ruby without rails? | by Daniel Martin | Nov, 2024 - Medium
web development with ruby without rails? | by Daniel Martin | Nov, 2024  Medium

The only 4 steps you need to take to learn web development - Fortune
The only 4 steps you need to take to learn web development  Fortune

Will Ukraine nuke Russia if Donald Trump cuts aide? Reports say the country is just months away from build - The Economic Times
Will Ukraine nuke Russia if Donald Trump cuts aide? Reports say the country is just months away from build  The Economic Times

From accounting to web development: Meet this Ironhack grad making big strides in programming - Refresh Miami
From accounting to web development: Meet this Ironhack grad making big strides in programming  Refresh Miami

5 Best Online Full-Stack Bootcamps Of 2024 - Forbes
5 Best Online Full-Stack Bootcamps Of 2024  Forbes

Northeastern grad goes from schooling to working full time at web development startup he created - Northeastern University
Northeastern grad goes from schooling to working full time at web development startup he created  Northeastern University

How To Make A Small Business Website In 2024 - Forbes
How To Make A Small Business Website In 2024  Forbes

15 Critical Security Tips for Web Development in 2024 - Netguru
15 Critical Security Tips for Web Development in 2024  Netguru

AI and the Web Developer's Future - CMSWire
AI and the Web Developer's Future  CMSWire

Are web developers not as relevant right now? What is the deal? - SitePoint
Are web developers not as relevant right now? What is the deal?  SitePoint

How Much Does A Website Cost? (2024 Guide) - Forbes
How Much Does A Website Cost? (2024 Guide)  Forbes

10 Web Development and Design Conferences To Know & Attend in 2024 - DesignRush
10 Web Development and Design Conferences To Know & Attend in 2024  DesignRush

Woocommerce_before_shop_loop related - SitePoint
Woocommerce_before_shop_loop related  SitePoint

University Libraries IT hosts web development workshop - UNM Newsroom
University Libraries IT hosts web development workshop  UNM Newsroom

10 Essential Web Development Tools for Streamlined Projects in 2024 - Netguru
10 Essential Web Development Tools for Streamlined Projects in 2024  Netguru

Top 25 Back-End Web Development Tools - Netguru
Top 25 Back-End Web Development Tools  Netguru

Must have skills for a pro web designer in 2024? - SitePoint
Must have skills for a pro web designer in 2024?  SitePoint

Megh Technologies Launches Website and Web App for Universal - openPR
Megh Technologies Launches Website and Web App for Universal  openPR

Build websites and digital services - GSA
Build websites and digital services  GSA

17 Best Tech Website Designs in 2024 - DesignRush
17 Best Tech Website Designs in 2024  DesignRush

The future of programming - SitePoint
The future of programming  SitePoint

StackBlitz Bolt.new blurs boundaries between web development and skilled use of AI prompts - DevClass
StackBlitz Bolt.new blurs boundaries between web development and skilled use of AI prompts  DevClass

10 Best Website Builders Of 2024 - Forbes
10 Best Website Builders Of 2024  Forbes

Earning A Web Developer Associate Degree - Forbes
Earning A Web Developer Associate Degree  Forbes

Register for AIM’s Free Web Development Course by Sept. 10 - Silicon Prairie News
Register for AIM’s Free Web Development Course by Sept. 10  Silicon Prairie News

How can I find clients for website development - SitePoint
How can I find clients for website development  SitePoint

Most used languages among software developers globally 2024 - Statista
Most used languages among software developers globally 2024  Statista

9 Cheapest Website Builders In 2024 - Forbes
9 Cheapest Website Builders In 2024  Forbes

Would You Use AI To Develop a Website? It's Easier Than You Think - How-To Geek
Would You Use AI To Develop a Website? It's Easier Than You Think  How-To Geek

How Much does Website Development Cost in 2022? - Appinventiv
How Much does Website Development Cost in 2022?  Appinventiv

Most used web frameworks among developers worldwide, as of 2024 - Statista
Most used web frameworks among developers worldwide, as of 2024  Statista

Web Hosting Services Market Projected to Reach $183 Billion - openPR
Web Hosting Services Market Projected to Reach $183 Billion  openPR

Latest News: Rising Senior Uses Computer Science Coursework to Thrive in Web Development Role - Muhlenberg College
Latest News: Rising Senior Uses Computer Science Coursework to Thrive in Web Development Role  Muhlenberg College

Data display problem - SitePoint
Data display problem  SitePoint

Wordpress-Gutenberg/React: MediaUpload? - SitePoint
Wordpress-Gutenberg/React: MediaUpload?  SitePoint

Best Website Development Tools for 2024 - DesignRush
Best Website Development Tools for 2024  DesignRush

Web Development Frameworks, Tools and Techniques for 2024 - Netguru
Web Development Frameworks, Tools and Techniques for 2024  Netguru

10 of the highest-paying web developer jobs right now - Fortune
10 of the highest-paying web developer jobs right now  Fortune

My search filter is malfunctioning - JavaScript - SitePoint
My search filter is malfunctioning - JavaScript  SitePoint

Top 40+ Web Developer Interview Questions and Answers for 2025 - Simplilearn
Top 40+ Web Developer Interview Questions and Answers for 2025  Simplilearn

Best web development tool of 2024 - TechRadar
Best web development tool of 2024  TechRadar

Webflow Debuts Industry-First Website Experience Platform (WXP), Superpowers Web Development with New AI Products, Tools, and Capabilities - PR Newswire
Webflow Debuts Industry-First Website Experience Platform (WXP), Superpowers Web Development with New AI Products, Tools, and Capabilities  PR Newswire

The 5 Best Web Development Courses Worth Taking in 2024 - TechRepublic
The 5 Best Web Development Courses Worth Taking in 2024  TechRepublic

Lazy AI: Revolutionizing Web Development with Claude's AI-Powered Code Generation - Anthropic
Lazy AI: Revolutionizing Web Development with Claude's AI-Powered Code Generation  Anthropic

Best Coding Bootcamps Online Of 2024 - Forbes
Best Coding Bootcamps Online Of 2024  Forbes

Best PHP Frameworks for Web Development in 2024 - Simplilearn
Best PHP Frameworks for Web Development in 2024  Simplilearn

10 Best SEO Services Of 2024 - Forbes
10 Best SEO Services Of 2024  Forbes

How to Use Node Js for Backend Web Development in 2024 - Simplilearn
How to Use Node Js for Backend Web Development in 2024  Simplilearn

How I Made $480,000 Through Web Development and Returned to SEO - hackernoon.com
How I Made $480,000 Through Web Development and Returned to SEO  hackernoon.com

Best web design software of 2024 - TechRadar
Best web design software of 2024  TechRadar

26 Best APAC Web and Software Development Companies (2024) - DesignRush
26 Best APAC Web and Software Development Companies (2024)  DesignRush

MERN Stack Explained: A Beginner's Guide [2025] - Simplilearn
MERN Stack Explained: A Beginner's Guide [2025]  Simplilearn

Website Dimensions: The Most Common Screen Resolutions To Design For in 2024 - DesignRush
Website Dimensions: The Most Common Screen Resolutions To Design For in 2024  DesignRush

38 Web Development Stats You Should Know in 2024 - Influencer Marketing Hub
38 Web Development Stats You Should Know in 2024  Influencer Marketing Hub

Top Website Statistics For 2024 - Forbes
Top Website Statistics For 2024  Forbes

WordPress Script Isn't Working - SitePoint
WordPress Script Isn't Working  SitePoint

Best laptops for programming of 2024 - TechRadar
Best laptops for programming of 2024  TechRadar

The future of web development: AWS Amplify’s Code First Approach - AWS Blog
The future of web development: AWS Amplify’s Code First Approach  AWS Blog

DesignRush Shortlists the Most Competitive Web Development Companies in October 2024 - DesignRush
DesignRush Shortlists the Most Competitive Web Development Companies in October 2024  DesignRush

Unlock Your Creativity: Building and Testing Websites in the Ubuntu Web Development Playground - Linux Journal
Unlock Your Creativity: Building and Testing Websites in the Ubuntu Web Development Playground  Linux Journal

You could build the next great website: These 5 bootcamps can help you become the next master web developer - Fortune
You could build the next great website: These 5 bootcamps can help you become the next master web developer  Fortune

How To Design A Website (2024 Guide) - Forbes
How To Design A Website (2024 Guide)  Forbes

60+ Angular Interview Questions in 2025: Prepare Like a Pro - Simplilearn
60+ Angular Interview Questions in 2025: Prepare Like a Pro  Simplilearn

Top Web Design Trends in 2024 - Netguru
Top Web Design Trends in 2024  Netguru

World Bank Group - International Development, Poverty and Sustainability - World Bank Group
World Bank Group - International Development, Poverty and Sustainability  World Bank Group

Python vs. C # : A Comprehensive Guide for 2024 - Netguru
Python vs. C # : A Comprehensive Guide for 2024  Netguru

New Web Development Tool Pulls Design Tokens From Figma - The New Stack
New Web Development Tool Pulls Design Tokens From Figma  The New Stack

Is_dir across drive from C: to D - SitePoint
Is_dir across drive from C: to D  SitePoint

DesignRush Unveils the Best Web Development Companies in July 2024 - DesignRush
DesignRush Unveils the Best Web Development Companies in July 2024  DesignRush

CSS prevents page scrolling - SitePoint
CSS prevents page scrolling  SitePoint

Back-end Web Development with .NET for Beginners - Microsoft
Back-end Web Development with .NET for Beginners  Microsoft

Top 10 Front End Languages - A Beginner's Guide - Simplilearn
Top 10 Front End Languages - A Beginner's Guide  Simplilearn

B2B Website Development Cost (2024) - DesignRush
B2B Website Development Cost (2024)  DesignRush

35 Best Web Design Companies 2024 - Built In
35 Best Web Design Companies 2024  Built In

10 Chicago Web Design and Development Agencies You Should Know - Built In Chicago
10 Chicago Web Design and Development Agencies You Should Know  Built In Chicago

How to Build Web Apps in 2024? A Step-by-Step Guide - Netguru
How to Build Web Apps in 2024? A Step-by-Step Guide  Netguru


Track Your Visitors, Using PHP


There are many different traffic analysis tools, ranging from simple counters to complete traffic analyzers. Although there are some free ones, most of them come with a price tag. Why not do it yourself? With PHP, you can easily create a log file within minutes. In this article I will show you how!

Getting the information

The most important part is getting the information from your visitor. Thankfully, this is extremely easy to do in PHP (or any other scripting language for that matter). PHP has a special global variable called $_SERVER which contains several environment variables, including information about your visitor. To get all the information you want, simply use the following code:

// Getting the information

$ipaddress = $_SERVER['REMOTE_ADDR'];

$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";

$page .= iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", "");

$referrer = $_SERVER['HTTP_REFERER'];

$datetime = mktime();

$useragent = $_SERVER['HTTP_USER_AGENT'];

$remotehost = @getHostByAddr($ipaddress);

As you can see the majority of information comes from the $_SERVER variable. The mktime() (http://nl2.php.net/mktime) and getHostByAddr() (http://nl2.php.net/manual/en/function.gethostbyaddr.php) functions are used to get additional information about the visitor.

Note: I used a function in the above example called iif(). You can get this function at http://www.phpit.net/code/iif-function.

Logging the information

Now that you have all the information you need, it must be written to a log file so you can later look at it, and create useful graphs and charts. To do this you need a few simple PHP function, like fopen (http://www.php.net/fopen) and fwrite (http://www.php.net/fwrite).

The below code will first create a complete line out of all the information. Then it will open the log file in "Append" mode, and if it doesn't exist yet, create it.

If no errors have occurred, it will write the new logline to the log file, at the bottom, and finally close the log file again.

// Create log line

$logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . "";

// Write to log file:

$logfile = '/some/path/to/your/logfile.txt';

// Open the log file in "Append" mode

if (!$handle = fopen($logfile, 'a+')) {

die("Failed to open log file");

}

// Write $logline to our logfile.

if (fwrite($handle, $logline) === FALSE) {

die("Failed to write to log file");

}

fclose($handle);

Now you've got a fully function logging module. To start tracking visitors on your website simply include the logging module into your pages with the include() function (http://www.php.net/include):

include ('log.php');

Okay, now I want to view my log file

After a while you'll probably want to view your log file. You can easily do so by simply using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.

Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:

// Open log file

$logfile = "/some/path/to/your/logfile.txt";

if (file_exists($logfile)) {

$handle = fopen($logfile, "r");

$log = fread($handle, filesize($logfile));

fclose($handle);

} else {

die ("The log file doesn't exist!");

}

Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:

// Seperate each logline

$log = explode("", trim($log));

After that it may be useful to get each part of each logline in a separate variable. This can be done by looping through each logline, and using explode again:

// Seperate each part in each logline

for ($i = 0; $i < count($log); $i++) {

$log[$i] = trim($log[$i]);

$log[$i] = explode('|', $log[$i]);

}

Now the complete log file has been parsed, and we're ready to start generating some interesting stuff.

The first thing that is very easy to do is getting the number of pageviews. Simply use count() (http://www.phpit.net/count) on the $log array, and there you have it;

echo count($log) . " people have visited this website.";

You can also generate a complete overview of your log file, using a simple foreach loop and tables. For example:

// Show a table of the logfile

echo '';

echo 'IP Address';

echo 'Referrer';

echo 'Date';

echo 'Useragent';

echo 'Remote Host';

foreach ($log as $logline) {

echo '

' . $logline['0'] . '' . urldecode($logline['1']) . '' . date('d/m/Y', $logline['2']) . '' . $logline['3'] . '' . $logline['4'] . '
home | site map
© 2006