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:
Web Performance Optimization (WPO) Solution Market Set for Exceptional Growth from 2024 to 2032 - openPR
Web Performance Optimization (WPO) Solution Market Set for Exceptional Growth from 2024 to 2032  openPR

Web Development Trends in 2024: A Shift Back to Simplicity - The New Stack
Web Development Trends in 2024: A Shift Back to Simplicity  The New Stack

Where to sell a website? - SitePoint
Where to sell a website?  SitePoint

Best laptops for programming of 2025 - TechRadar
Best laptops for programming of 2025  TechRadar

An Eye for Art: Westminster artist uses creative skills in web development - Baltimore Sun
An Eye for Art: Westminster artist uses creative skills in web development  Baltimore Sun

Final Year Projects for Computer Science: Innovative Ideas - Simplilearn
Final Year Projects for Computer Science: Innovative Ideas  Simplilearn

Responsive Design Courses to Ensure Multi-Device Compatibility for UI Developers - Shiksha Online
Responsive Design Courses to Ensure Multi-Device Compatibility for UI Developers  Shiksha Online

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

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

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

12 Web Development Trends To Watch in 2025 - Shopify
12 Web Development Trends To Watch in 2025  Shopify

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

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

Front End Developer Skills and Responsibilities - Simplilearn
Front End Developer Skills and Responsibilities  Simplilearn

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

Rediscover the Joy of Early Web Development With XSLT - The New Stack
Rediscover the Joy of Early Web Development With XSLT  The New Stack

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

The looming disaster of AI - SitePoint
The looming disaster of AI  SitePoint

Key Web Developer Skills to Boost Your Portfolio 2025 - Simplilearn
Key Web Developer Skills to Boost Your Portfolio 2025  Simplilearn

Frontend Costs: The Essential Guide to Website Development in 2024 - Netguru
Frontend Costs: The Essential Guide to Website Development in 2024  Netguru

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

23 In-Demand Full Stack Developer Skills in 2025 - Simplilearn
23 In-Demand Full Stack Developer Skills in 2025  Simplilearn

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

HTML, CSS, and you: 5 YouTube channels to learn hands-on web development - The Daily Star
HTML, CSS, and you: 5 YouTube channels to learn hands-on web development  The Daily Star

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

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

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

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

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

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

The Rock It! Co. earns Gold Award in Web Development - The Post and Courier
The Rock It! Co. earns Gold Award in Web Development  The Post and Courier

Unlock Top-Tier Mobile App Development with Skilled Developers at eBizneeds - EIN News
Unlock Top-Tier Mobile App Development with Skilled Developers at eBizneeds  EIN News

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

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

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

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

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

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

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

How do I fix this? - SitePoint
How do I fix this?  SitePoint

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

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

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

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

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

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

【react roulette】 Português - Agência Brasília
【react roulette】 Português  Agência Brasília

Best web development tool of 2025 - TechRadar
Best web development tool of 2025  TechRadar

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

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

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

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

15 Best Bay Area Web Design & Development Agencies (2025) - DesignRush
15 Best Bay Area Web Design & Development Agencies (2025)  DesignRush

Top 10 Frontend Development Trends in 2024 - Netguru
Top 10 Frontend Development Trends in 2024  Netguru

CSS5 Features for Faster Web Design - Analytics Insight
CSS5 Features for Faster Web Design  Analytics Insight

Top Web Design Trends for 2025 - Designmodo
Top Web Design Trends for 2025  Designmodo

RoR vs Node.js: A Comparison of Frameworks for Web Development in 2023 - Netguru
RoR vs Node.js: A Comparison of Frameworks for Web Development in 2023  Netguru

How an India-Based Web Developer Quit His Day Job and Built an Agency - Shopify
How an India-Based Web Developer Quit His Day Job and Built an Agency  Shopify

Your Guide To the Best Backend Languages For 2025 - Simplilearn
Your Guide To the Best Backend Languages For 2025  Simplilearn

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

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

Top Web Design Trends in 2024 - Netguru
Top Web Design Trends in 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

HTML6 and CSS5: What’s New for Web Developers? - Analytics Insight
HTML6 and CSS5: What’s New for Web Developers?  Analytics Insight

Web Developer's Guide to the 2024 Esri Developer Summit - Esri
Web Developer's Guide to the 2024 Esri Developer Summit  Esri

The birth of the Web - CERN
The birth of the Web  CERN

Can Generative AI Replace Coding? A Data Scientist's Attempt at Web Development - substack.com
Can Generative AI Replace Coding? A Data Scientist's Attempt at Web Development  substack.com

Improve Your Web App Performance: 11 Tips for 2024 - Netguru
Improve Your Web App Performance: 11 Tips for 2024  Netguru

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

Azerbaijan's State Agency to attract website development services via tender - Trend News Agency
Azerbaijan's State Agency to attract website development services via tender  Trend News Agency

11 Applications and Uses of Python in 2025 - Simplilearn
11 Applications and Uses of Python in 2025  Simplilearn

Best Web Development Courses (2024): Top Udemy Online Web Development Courses With Certificates Reviewed by Compare Before Buying - Business Wire
Best Web Development Courses (2024): Top Udemy Online Web Development Courses With Certificates Reviewed by Compare Before Buying  Business Wire

Best website design service of 2025 - TechRadar
Best website design service of 2025  TechRadar

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

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

8 Top Python Web App Examples From Top-Notch Companies - Netguru
8 Top Python Web App Examples From Top-Notch Companies  Netguru

The best web development classes, bootcamps, and certifications near me - Time Out
The best web development classes, bootcamps, and certifications near me  Time Out

8 Inspiring Website Design Examples for Small Businesses (2024) - Shopify
8 Inspiring Website Design Examples for Small Businesses (2024)  Shopify

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

WasmGC and the future of front-end Java development - InfoWorld
WasmGC and the future of front-end Java development  InfoWorld

How To Become A Entry-Level Web Developer in 2024 - Simplilearn
How To Become A Entry-Level Web Developer in 2024  Simplilearn

Web of Science Research Assistant - Clarivate
Web of Science Research Assistant  Clarivate

26 Best APAC Web and Software Development Companies in 2025 - DesignRush
26 Best APAC Web and Software Development Companies in 2025  DesignRush

PhyloJS: Bridging phylogenetics and web development with a JavaScript utility library - Wiley Online Library
PhyloJS: Bridging phylogenetics and web development with a JavaScript utility library  Wiley Online Library

Top 70+ C# Interview Questions: Your Guide to Success - Simplilearn
Top 70+ C# Interview Questions: Your Guide to Success  Simplilearn

How to Become a Python Developer - Required Skills [2024] - Simplilearn
How to Become a Python Developer - Required Skills [2024]  Simplilearn

How to Run a PHP File Using XAMPP: A Step By Step Guide - Simplilearn
How to Run a PHP File Using XAMPP: A Step By Step Guide  Simplilearn

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

25 Examples Of About Us Pages For Inspiration - Search Engine Journal
25 Examples Of About Us Pages For Inspiration  Search Engine Journal

18 stunning parallax scrolling websites - Creative Bloq
18 stunning parallax scrolling websites  Creative Bloq

Best Web Development Bootcamp (2024): Udemy Complete Python Pro Bootcamp Review by Compare Before Buying - Business Wire
Best Web Development Bootcamp (2024): Udemy Complete Python Pro Bootcamp Review by Compare Before Buying  Business Wire

Full-stack web development with HTMX and Bun, Part 2: Pug templating - InfoWorld
Full-stack web development with HTMX and Bun, Part 2: Pug templating  InfoWorld

【react roulette】 Português - Agência Brasília
【react roulette】 Português  Agência Brasília

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

Digital marketing firm inks merger deal with local company - The Business Journals
Digital marketing firm inks merger deal with local company  The Business Journals

KWDK Introduces Groundbreaking Innovations in Web Development and Digital Marketing - Yahoo Finance
KWDK Introduces Groundbreaking Innovations in Web Development and Digital Marketing  Yahoo Finance

Best laptop for graphic design in 2024: top picks for every budget - TechRadar
Best laptop for graphic design in 2024: top picks for every budget  TechRadar

How to Use ChatGPT to Build a Website - Themeisle
How to Use ChatGPT to Build a Website  Themeisle

10 Best Programming Languages for Software Development in 2024 - Netguru
10 Best Programming Languages for Software Development in 2024  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