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:
Top 25 Back-End Web Development Tools - Netguru
Top 25 Back-End Web Development Tools  Netguru

Securing WebAssembly in Web Development - NASSCOM Community
Securing WebAssembly in Web Development  NASSCOM Community

accessiBe Launches accessFlow, Comprehensive Tool for Driving Native Accessibility in Web Development Projects - PR Newswire
accessiBe Launches accessFlow, Comprehensive Tool for Driving Native Accessibility in Web Development Projects  PR Newswire

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

Top 5 Uses of WebAssembly for Web Developers - The New Stack
Top 5 Uses of WebAssembly for Web Developers  The New Stack

Top 15 Front-End Technologies in 2025 - DesignRush
Top 15 Front-End Technologies in 2025  DesignRush

Best Website Builder and Design Service Reviews of 2025 - Business.com
Best Website Builder and Design Service Reviews of 2025  Business.com

12 Essential Atom Packages for Web Development - SitePoint
12 Essential Atom Packages for Web Development  SitePoint

Dynamic web apps with HTMX, Python, and Django - InfoWorld
Dynamic web apps with HTMX, Python, and Django  InfoWorld

Elon Musk’s DOGE website has been defaced because anyone can edit it - The Verge
Elon Musk’s DOGE website has been defaced because anyone can edit it  The Verge

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

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

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

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

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

Top Web Developer Interview Questions and Answers (2025) - Simplilearn
Top Web Developer Interview Questions and Answers (2025)  Simplilearn

Python’s Frameworks Comparison: Django, Pyramid, Flask, Sanic, Tornado, BottlePy and More - Netguru
Python’s Frameworks Comparison: Django, Pyramid, Flask, Sanic, Tornado, BottlePy and More  Netguru

16 Top Web Development Trends in 2025 - Netguru
16 Top Web Development Trends in 2025  Netguru

Web App Development Cost: Comprehensive Guide for 2025 - Netguru
Web App Development Cost: Comprehensive Guide for 2025  Netguru

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

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

DOGE.gov Debacle: How a Government Website Went to the Dogs and What It Means for Cybersecurity - Security Boulevard
DOGE.gov Debacle: How a Government Website Went to the Dogs and What It Means for Cybersecurity  Security Boulevard

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

Essential Web Developer Skills for 2025 - Simplilearn
Essential Web Developer Skills for 2025  Simplilearn

Elon Musk's DOGE Website Database Vulnerability Let Anyone Make Entries Directly - CybersecurityNews
Elon Musk's DOGE Website Database Vulnerability Let Anyone Make Entries Directly  CybersecurityNews

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

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

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

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

The Future Role of AI in Web Development: What to Expect - DesignRush
The Future Role of AI in Web Development: What to Expect  DesignRush

100 Programming Languages List & Best Ones to Learn - Simplilearn
100 Programming Languages List & Best Ones to Learn  Simplilearn

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

20 Most Popular Python IDEs in 2025: Code Like a Pro - Simplilearn
20 Most Popular Python IDEs in 2025: Code Like a Pro  Simplilearn

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

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 Much does Website Development Cost in 2022? - Appinventiv
How Much does Website Development Cost in 2022?  Appinventiv

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

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

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

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

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

Understanding Web 4.0: The Future of an Intelligent Internet - Netguru
Understanding Web 4.0: The Future of an Intelligent Internet  Netguru

3 Python web frameworks for beautiful front ends - InfoWorld
3 Python web frameworks for beautiful front ends  InfoWorld

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 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

The Rise of Rust and WebAssembly in Web Development - The New Stack
The Rise of Rust and WebAssembly in Web Development  The New Stack

24 Top Frontend Technologies to Use in 2025 - Netguru
24 Top Frontend Technologies to Use in 2025  Netguru

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

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

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

Top Web Frameworks to Learn and Tips to Build a Career in Web Development - Simplilearn
Top Web Frameworks to Learn and Tips to Build a Career in Web Development  Simplilearn

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

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

20 Best Twin Cities Web Design & Development Agencies in 2025 - DesignRush
20 Best Twin Cities Web Design & Development Agencies in 2025  DesignRush

The Ultimate Guide to Python Web Development for 2024 - Simplilearn
The Ultimate Guide to Python Web Development for 2024  Simplilearn

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

Top 10 Web Development Tools and Tips to Become a Successful Web Developer - Simplilearn
Top 10 Web Development Tools and Tips to Become a Successful Web Developer  Simplilearn

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

DesignRush Reveals the Top Web Development Agencies in December 2024 - DesignRush
DesignRush Reveals the Top Web Development Agencies in December 2024  DesignRush

Golang Crash Course Part 7- Web Development in Go | by Ben Meehan | Jan, 2025 - Medium
Golang Crash Course Part 7- Web Development in Go | by Ben Meehan | Jan, 2025  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

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

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

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

Is Web Development Approaching Its Peak as We Head Into 2025? - IoT Business News
Is Web Development Approaching Its Peak as We Head Into 2025?  IoT Business News

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

HeartCore Partners with NTT Data Business Brains - GlobeNewswire
HeartCore Partners with NTT Data Business Brains  GlobeNewswire

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

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

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

Web Design Statistics By UI/UX, Market Size, Web Development, Industry and Demographics - Coolest Gadgets
Web Design Statistics By UI/UX, Market Size, Web Development, Industry and Demographics  Coolest Gadgets

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

Accelerate web application development and ROI with Microsoft Power Pages - Microsoft
Accelerate web application development and ROI with Microsoft Power Pages  Microsoft

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

Best Web Design Companies Toronto - Search Engine People
Best Web Design Companies Toronto  Search Engine People

15 Best Lehigh Valley Web Design & Development Agencies for 2025 - DesignRush
15 Best Lehigh Valley Web Design & Development Agencies for 2025  DesignRush

Where web developers are commanding the biggest salaries - Fortune
Where web developers are commanding the biggest salaries  Fortune

Learn CSS Box Model and its Properties with Examples - Simplilearn
Learn CSS Box Model and its Properties with Examples  Simplilearn

How to Simulate Mobile Devices with Device Mode in Chrome - SitePoint
How to Simulate Mobile Devices with Device Mode in Chrome  SitePoint

Expert Predictions for Web Development in 2025 - TechRound
Expert Predictions for Web Development in 2025  TechRound

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

Florida Keys Tourism Council seeks advertising, web development services providers - KeysNews.com
Florida Keys Tourism Council seeks advertising, web development services providers  KeysNews.com

Generative AI for Web Developers - O'Reilly Media
Generative AI for Web Developers  O'Reilly Media

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

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

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

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

Web Development | Website Design for Yachting Companies - Yachting Pages
Web Development | Website Design for Yachting Companies  Yachting Pages

An In-Depth Comparison of Node.js vs. PHP in 2023 - Netguru
An In-Depth Comparison of Node.js vs. PHP in 2023  Netguru

Free Internship 2025 on Python | AI | ML | Data Science | Web Development! - Sakshi Education English
Free Internship 2025 on Python | AI | ML | Data Science | Web Development!  Sakshi Education English

The best websites for finding developers - Business.com
The best websites for finding developers  Business.com

10 Must-Have WordPress Website Design Tools in 2025 - DesignRush
10 Must-Have WordPress Website Design Tools in 2025  DesignRush

11 Best Interactive Website Designs in 2025 - DesignRush
11 Best Interactive Website Designs in 2025  DesignRush

How to Build a Stunning Portfolio Website as a Web Developer - SitePoint
How to Build a Stunning Portfolio Website as a Web Developer  SitePoint

What is HTTP/3? The next-generation web protocol - InfoWorld
What is HTTP/3? The next-generation web protocol  InfoWorld

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

Introducing the Edge 2024 web platform top developer needs dashboard - Windows Blog
Introducing the Edge 2024 web platform top developer needs dashboard  Windows Blog

KWDK Introduces Groundbreaking Innovations in Web Development and Digital Marketing - GlobeNewswire
KWDK Introduces Groundbreaking Innovations in Web Development and Digital Marketing  GlobeNewswire

Developer Tools: What’s Ahead in 2025? - The New Stack
Developer Tools: What’s Ahead in 2025?  The New Stack

Top 10 Java Backend Frameworks in 2024 - Netguru
Top 10 Java Backend Frameworks 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