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:
Ignite Visibility Acquires Outliant, a Leading Web Development Agency - PRWeb
Ignite Visibility Acquires Outliant, a Leading Web Development Agency  PRWeb

Web Developer - Sahan Journal
Web Developer  Sahan Journal

JetRockets Earns Spot as Best of Clutch Finalist in Web Development & Web Design Category - PR.com
JetRockets Earns Spot as Best of Clutch Finalist in Web Development & Web Design Category  PR.com

Enterprise Web Dev IT Monks Levels Up with WordPress VIP Silver Partnership - Reuters
Enterprise Web Dev IT Monks Levels Up with WordPress VIP Silver Partnership  Reuters

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

Web Design, Development and Email Marketing Blog - Designmodo
Web Design, Development and Email Marketing Blog  Designmodo

Rate my website - SitePoint
Rate my website  SitePoint

Why Senior Developers Are Abandoning Traditional Web Development | by Abduldattijo | Apr, 2025 - DataDrivenInvestor
Why Senior Developers Are Abandoning Traditional Web Development | by Abduldattijo | Apr, 2025  DataDrivenInvestor

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

Students learn web designing, security - The Tribune
Students learn web designing, security  The Tribune

Web development: The new TypeScript compiler in Go - heise online
Web development: The new TypeScript compiler in Go  heise online

How digital excellence drives business growth: Lessons from award-winning web development projects - AZ Big Media
How digital excellence drives business growth: Lessons from award-winning web development projects  AZ Big Media

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

The Top Accounting AI Agents I’d Recommend: A Hands‑On Review - DesignRush
The Top Accounting AI Agents I’d Recommend: A Hands‑On Review  DesignRush

Top 21 Developer Newsletters to Subscribe To in 2025 - SitePoint
Top 21 Developer Newsletters to Subscribe To in 2025  SitePoint

I Tested the Top 5 AI Web Design Tools: Here's How They Stack Up - DesignRush
I Tested the Top 5 AI Web Design Tools: Here's How They Stack Up  DesignRush

DesignRush Handpicks the Best Digital Marketing Agencies in April 2025 - DesignRush
DesignRush Handpicks the Best Digital Marketing Agencies in April 2025  DesignRush

Rachael Katie Cosmetics Website Design Analysis - DesignRush
Rachael Katie Cosmetics Website Design Analysis  DesignRush

After Testing the 20 Most Popular AI Tools, Here’s What I Learned - DesignRush
After Testing the 20 Most Popular AI Tools, Here’s What I Learned  DesignRush

I Explored 5 AI Design Agents for Faster, Smarter Design Workflows - DesignRush
I Explored 5 AI Design Agents for Faster, Smarter Design Workflows  DesignRush

DeKalb library to hold web development class April 21 - Shaw Local
DeKalb library to hold web development class April 21  Shaw Local

Why Custom Web Development Beats Templates? - Harlem World Magazine
Why Custom Web Development Beats Templates?  Harlem World Magazine

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

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

Launch Your Professional Website in Minutes: No Coding Required - HackerNoon
Launch Your Professional Website in Minutes: No Coding Required  HackerNoon

Web - Pacific Lutheran University
Web  Pacific Lutheran University

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

Web Performance Market Forecasted to Reach USD 10.45 Bn by 2030, with a CAGR of 8.69% from 2024 to 2030 - openPR.com
Web Performance Market Forecasted to Reach USD 10.45 Bn by 2030, with a CAGR of 8.69% from 2024 to 2030  openPR.com

AI in Web Development: Enhancing Websites with Smart Chatbot Integration - NASSCOM Community
AI in Web Development: Enhancing Websites with Smart Chatbot Integration  NASSCOM Community

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

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

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

Grant being offered to Tazewell County businesses for web development - WVVA
Grant being offered to Tazewell County businesses for web development  WVVA

Best Coding Bootcamps Online Of 2025 - Forbes
Best Coding Bootcamps Online Of 2025  Forbes

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

Weyra Academy Launches 6-Week Web Development Course to Build Ethiopia’s Digital Workforce - Addis Insight
Weyra Academy Launches 6-Week Web Development Course to Build Ethiopia’s Digital Workforce  Addis Insight

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

Download WampServer (free) for Windows - Gizmodo
Download WampServer (free) for Windows  Gizmodo

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

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

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

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

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

18 Best Tech Website Designs in 2025 - DesignRush
18 Best Tech Website Designs in 2025  DesignRush

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

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

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

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

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

Student web designers put the flex in UX - Clark University
Student web designers put the flex in UX  Clark University

The Future of Web Development: Trends and Technologies on the Horizon - IoT Business News
The Future of Web Development: Trends and Technologies on the Horizon  IoT Business News

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

Best PHP Frameworks for Web Development in 2025 - Simplilearn.com
Best PHP Frameworks for Web Development in 2025  Simplilearn.com

Top 10 Java Backend Frameworks in 2025 - Netguru
Top 10 Java Backend Frameworks in 2025  Netguru

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

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

12 Web Development Trends To Watch in 2025 - Shopify
12 Web Development Trends To Watch in 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

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

"I'm 22 years old, and I'm looking for a way to avoid being a beggar in my old age. I feel like I've been studying the web for 2-3 years for nothing." A young developer asked the community if AI will really replace programmers: a discussion with 150 comments - dev.ua
"I'm 22 years old, and I'm looking for a way to avoid being a beggar in my old age. I feel like I've been studying the web for 2-3 years for nothing." A young developer asked the community if AI will really replace programmers: a discussion with 150 comments  dev.ua

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

Is Frontend Development Dying? Exploring the Future - Netguru
Is Frontend Development Dying? Exploring the Future  Netguru

Empowering UAE Startups: DianApps introduces end-to-end mobile and web development services - ZAWYA
Empowering UAE Startups: DianApps introduces end-to-end mobile and web development services  ZAWYA

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

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

Know How to Add CSS to HTML with Examples - Simplilearn.com
Know How to Add CSS to HTML with Examples  Simplilearn.com

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Web 1.0, 2.0, 3.0, & 4.0: A Detailed Guide - Simplilearn.com
Web 1.0, 2.0, 3.0, & 4.0: A Detailed Guide  Simplilearn.com

How to Create a Navigation Bar With HTML and CSS - Simplilearn.com
How to Create a Navigation Bar With HTML and CSS  Simplilearn.com

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

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

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

Comprehensive Review of '​AI Strategies for Web Development' by Sunil Raj Thota - Packt
Comprehensive Review of '​AI Strategies for Web Development' by Sunil Raj Thota  Packt

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

Software & Support Media acquires a majority stake in NLJUG B.V. - devmio
Software & Support Media acquires a majority stake in NLJUG B.V.  devmio

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

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

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

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

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

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

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

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

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

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


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