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:
Grant being offered to Tazewell County businesses for web development - WVVA
Grant being offered to Tazewell County businesses for web development  WVVA

PyScript vs. JavaScript: A Battle of Web Titans - Towards Data Science
PyScript vs. JavaScript: A Battle of Web Titans  Towards Data Science

Fake online shops rely on tech skills: what drives Cameroon’s web developers to assist online fraudsters - The Conversation
Fake online shops rely on tech skills: what drives Cameroon’s web developers to assist online fraudsters  The Conversation

8 Types of Node.js Apps You Can Build in 2025 - Netguru
8 Types of Node.js Apps You Can Build in 2025  Netguru

All things Web Development at the Esri Developer and Technology Summit 2025! - Esri
All things Web Development at the Esri Developer and Technology Summit 2025!  Esri

Why Businesses Choose Bilions: A Top Web and Software Development Company for Scalable Solutions - openPR.com
Why Businesses Choose Bilions: A Top Web and Software Development Company for Scalable Solutions  openPR.com

Vulnerability affecting Next.js web development framework - National Cyber Security Centre
Vulnerability affecting Next.js web development framework  National Cyber Security Centre

AI-Powered Website Builders: Real Results or Empty Promises? - Analytics Insight
AI-Powered Website Builders: Real Results or Empty Promises?  Analytics Insight

Digital Silk Unveils the Latest Web Development Trends - Newsfile
Digital Silk Unveils the Latest Web Development Trends  Newsfile

Prompt Engineering for Web Development - SitePoint
Prompt Engineering for Web Development  SitePoint

15 Web Development and Design Conferences To Join in 2025 - DesignRush
15 Web Development and Design Conferences To Join in 2025  DesignRush

How Wasm reinvents web development - InfoWorld
How Wasm reinvents web development  InfoWorld

Pagoda: A Web Development Starter Kit for Go Programmers - The New Stack
Pagoda: A Web Development Starter Kit for Go Programmers  The New Stack

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

11 Best Shoreditch Web Design and Development Agencies To Consider - DesignRush
11 Best Shoreditch Web Design and Development Agencies To Consider  DesignRush

Top 10 Frontend Trends in 2025 - Netguru
Top 10 Frontend Trends in 2025  Netguru

DesignRush Selects the Top Web Development Companies in March 2025 - DesignRush
DesignRush Selects the Top Web Development Companies in March 2025  DesignRush

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

10 Best Web Development Blogs Тo Follow in 2025 - DesignRush
10 Best Web Development Blogs Тo Follow in 2025  DesignRush

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

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

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

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

20 Best Manhattan Web Design & Development Agencies for 2025 - DesignRush
20 Best Manhattan Web Design & Development Agencies for 2025  DesignRush

Digital Silk Unveils Key Web Development Trends For 2025 - Evrim Ağacı
Digital Silk Unveils Key Web Development Trends For 2025  Evrim Ağacı

50 Essential Web Design Statistics Every Business Needs To Know in 2025 - DesignRush
50 Essential Web Design Statistics Every Business Needs To Know in 2025  DesignRush

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

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

HTMX and Alpine.js: How to combine two great, lean front ends - InfoWorld
HTMX and Alpine.js: How to combine two great, lean front ends  InfoWorld

How AI is Transforming Frontend Development in 2025? - Analytics Insight
How AI is Transforming Frontend Development in 2025?  Analytics Insight

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

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

Best Website Development Tools To Use in 2025 - DesignRush
Best Website Development Tools To Use in 2025  DesignRush

Plug-and-play web development with Astro - InfoWorld
Plug-and-play web development with Astro  InfoWorld

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

Meet Hostinger Horizons: A No-Code AI Tool that Lets You Create, Edit, and Publish Custom Web Apps Without Writing a Single Line of Code - MarkTechPost
Meet Hostinger Horizons: A No-Code AI Tool that Lets You Create, Edit, and Publish Custom Web Apps Without Writing a Single Line of Code  MarkTechPost

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

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

7 Practical Ways To Use AI in Web Development in 2025 - DesignRush
7 Practical Ways To Use AI in Web Development in 2025  DesignRush

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

Best Programming Languages to Learn in 2025 | Complete List - Simplilearn.com
Best Programming Languages to Learn in 2025 | Complete List  Simplilearn.com

The Rise of Rust and WebAssembly in Web Development - The New Stack
The Rise of Rust and WebAssembly in Web Development  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

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

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

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

10 Best Brooklyn Web Design and Development Agencies - DesignRush
10 Best Brooklyn Web Design and Development Agencies  DesignRush

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

How Much does Website Development Cost in 2022? - appinventiv.com
How Much does Website Development Cost in 2022?  appinventiv.com

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

Backend to the Frontline: Speeding Up Your Web Pages with Minimal Effort - devmio
Backend to the Frontline: Speeding Up Your Web Pages with Minimal Effort  devmio

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

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

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

Top 10 Coding Languages to Learn in 2025 - Education Times
Top 10 Coding Languages to Learn in 2025  Education Times

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

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

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

Top JavaScript Tools and Libraries to Boost Web Development in 2025 - HackerNoon
Top JavaScript Tools and Libraries to Boost Web Development in 2025  HackerNoon

Best Silicon Valley Web Design & Development Agencies That Deliver - DesignRush
Best Silicon Valley Web Design & Development Agencies That Deliver  DesignRush

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

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

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

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

10 Top Chrome Extensions for Your Web Development Workflow - SitePoint
10 Top Chrome Extensions for Your Web Development Workflow  SitePoint

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

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

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

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

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

Web Development Services - elixirrdigital.com
Web Development Services  elixirrdigital.com

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

Cot framework aims to ease Rust web development - InfoWorld
Cot framework aims to ease Rust web development  InfoWorld

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

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

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

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

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

The frontend web and mobile app developer’s guide to AWS re:Invent 2024 - Amazon Web Services
The frontend web and mobile app developer’s guide to AWS re:Invent 2024  Amazon Web Services

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 to Simulate Mobile Devices with Device Mode in Chrome - SitePoint
How to Simulate Mobile Devices with Device Mode in Chrome  SitePoint

Here Are The Top PHP Frameworks The Pros Use for Web Development - HackerNoon
Here Are The Top PHP Frameworks The Pros Use for Web Development  HackerNoon

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

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

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

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

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

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

16 Best Modern Website Designs of the Moment - DesignRush
16 Best Modern Website Designs of the Moment  DesignRush

Best laptop for programming of 2025: top picks tested for coding - TechRadar
Best laptop for programming of 2025: top picks tested for coding  TechRadar

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

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

Don’t Pick the Best Web Design Software Until You Try These 6 - Learn Hub | G2
Don’t Pick the Best Web Design Software Until You Try These 6  Learn Hub | G2

6 interesting facts about how web designers are using AI - TechRadar
6 interesting facts about how web designers are using AI  TechRadar

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

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

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

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

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

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


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