Your Ad Here

 Navigation
Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Books
Sample Chapters
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




 Sponsors
 Links
domain names
software directory
dvd information
 Downloads
dzphp editor
EasyPHP
mysql_phpgenerator
php-studio-trial
phpdesigner_7_2_5
phpMyAdmin-3.4.3.2
/phptriad2-2-1
phpxedit_321
rapidphp 2011
WampServer2.1d-x64
WampServer2.1e-x32
xampp-win32-1.7.4-VC6-installer
xampplite-win32-1.7.3
 Misc
Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!


Getting your Visitor's Details Using PHP


You can get quite a bit of information about your visitors without having to use a third party tracking software. I'll outline the PHP commands you can use to capture some of this data. The details you capture can be saved into a database, and retrieved later to check your site's performance and user details. The following information is captured using the server variable ($_SERVER) which is available from PHP 4.10 onwards.

Visitor's IP address :


You can get the visitor's IP address using the following command:




<? $ip = $_SERVER['HTTP_CLIENT_IP']; ?>


This will give you the vistor's IP address. You can use this along with an ip to country converter database to see from which country your visitors are come in from. You can head over to
http://ip-to-country.webhosting.info/ for one such script.


You can use PHP to resolve the ip address to a domain name to get the visitor's ISP in most cases. The ISP's domain will show up if PHP is able to resolve the IP to a proper domain. You can do this as follows.




<?

$ip = $_SERVER['HTTP_CLIENT_IP'];

$visitor_host = @getHostByAddr( $ip );

?>


Note : On some servers, using getHostByAddr to resolve domains may cause the script to slow down.


Referring Page :


You can capture the referring page, which will give you an indication of which site is sending traffic to you.




<? $referrer_page = $_SERVER['HTTP_REFERER']; ?>


This will give you the entire URL from which the visitor came to your site. For example if the visitor came from a google search for "i-pod", the referrer url would look something like this :


http://www.google.co.in/search?q=i-pod&hl=en&lr=&ie=UTF-8&start=50


If you don't want the entire URL captured, but just the domain name stored into the database, you can strip the rest of the URL and save it to the database like so:




<?

$referrer_page =

parse_url(htmlspecialchars(strip_tags($_SERVER['HTTP_REFERER'])));

?>


This will save the referring page as :


http://www.google.co.in/


The page being Accessed :


You can also capture the page being accessed on your server. This
information will help you evaluate which parts of your site is getting more page views.


A more advanced user can also use this information to create a
click-stream of the user. A click-stream is the path that a user
follows while he goes through your site. This lets you see how
effective your site's navigation is.




<? $requested_page = $_SERVER['REQUEST_URI']; ?>


If the visitor is accessing your page,
http://www.yourdomain.com/guestbook.php, the requested page would be 'guestbook.php'.


These pieces of information will help you build a visitor tracker in PHP, which will be able to tell you quite a bit about your visitors and how they use your site.



About the Author

Vinu Thomas is a consultant on Webdesign and Internet Technologies.

His website is http://www.vinuthomas.com

He is presently consulting http://www.indiaresortssurvey.com

Written by: Vinu Thomas

 



Here is our complete list of articles


Apache MySQL and PHP for Windows

Apache MySQL PHP for Windows

ASP CGI and PHP Scripts and Record Locking What Every Webmaster Needs To Know

Autoresponders With PHP

Bring Your Web Site to Life With PHP

Clickbank Security Using PHP

Create a Simple Effective PHP Form for Your Web Site

Creating Dynamic Website Content with PHP MySQL

Developing a Login System with PHP and MySQL

Developing State enabled Applications With PHP

For Automated Sites PHP and MySQL are A Perfect Match

Get PHP pages indexed in the Search engines

How PHP Can Help Save You Time And Mistakes

How to make a simple form mailer with PHP

HTACCESS Wrappers with PHP

Maguma has integrated support for the eBay Acellerator Toolkit for PHP PHP AT in their PHP IDE Maguma Workbench

Make a Search Engine For Your Website With PHP

Mastering Regular Expressions in PHP

More Autoresponders With PHP

MySQL Database Handling in PHP

ONLINE the eBay Accelerator Toolkit for PHP PHP AT for the PHP IDE Maguma Workbench is available

Password Protection and File Inclusion With PHP

Password Protection with PHP MySQL and Session Variables

PHP Account Activation

PHP and Cookies a Good Mix

PHP Auto surf Websites

PHP Databases

PHP Dynamic Content

PHP Email

PHP Encryption

PHP Error Pages

PHP Files

PHP Form Series Part 1 Validators Client side Validation

PHP General Scripting

PHP Image Gallery

PHP in the Command Line

PHP is 10 years old

PHP my favorite Server side Programming Technology

PHP On The Fly

PHP Pear Packages Why they are so important to php developers

PHP Redirect

PHP Scripts Dont Have to End in PHP

PHP Server to Client with No Refresh

PHP Sessions / Cookies

PHP Templates

PHP User Login Authentication

PIM Team Case Study Creating Text Effects With PHP and GD

Protecting your HTML and PHP Source Code

Quick Intro to PHP Development

Serialize this Saving Objects in PHP

Simple Solution for Php Includes IFrames

Site Personalization With PHP

Some PHP functions you must know

Track Your Visitors Using PHP

Victoryvisions The PHP/Mysql Company Complete website development company



Books
 Sponsors


 Random Code
Break out of a loop(beginner)
If Else statement(beginner)
Random Amazon book link(randomizing)
 Random Article
  Network
Programming resources
Tutorials directory
Hosting resources
ASP site
Domain names
Progged
Maxi directory
bigarticle : free articles
A Code
Code N Tutorials
Get PHP
Programmers help




beginners PHP Copyright © 2004 onwards by beginnersPHP.