As an owner of a web site or blog, you are always concerned about the security constraints. In this while, you must have thought that tracking the IP addresses of your blog or web site visitors, would solve your problem to a great extent. So, modern day bloggers and web site owners are very much concerned about maintaining a record of all the visiting IP addresses.
Apart from this, some of the web site owners wish to provide a separate widget on their site, to let his/her web site visitors know their IP addresses. This adds beauty to your web site and your visitors would surely love it. Now there are many ways by which you can track the information of your web site visitors. To find and display the IP address of your visitors, all you got to do is insert the code and you can make your visitors know their IP.
For PHP Users :
If you are using PHP server side programming and wondering how to track the IP addresses of the web site visitors, this is a useful PHP Function, which would display the IP address of your web site visitor.
To start with, you need to check your environment variable and make the changes (if required)
No Proxy detection
=> REMOTE_ADDR – Remote client IP address
With Proxy detection
=> HTTP_X_FORWARDED_FOR – Get Proxy server IP
PHP getenv() function
=> Use php getenv() function to read the value of the environment.
This piece of code can be added on your web site or blog to let your visitors know about their IP address :
<<html>
<head>
<title>What is my IP address?</title>
</head>
<body>
<?php
if (getenv(HTTP_X_FORWARDED_FOR)) {
$pipaddress = getenv(HTTP_X_FORWARDED_FOR);
$ipaddress = getenv(REMOTE_ADDR);
echo "Your Proxy IPaddress is : ".$pipaddress. "(via $ipaddress)" ;
} else {
$ipaddress = getenv(REMOTE_ADDR);
echo "Your IP address is : $ipaddress";
}
?>
</body>
</html>
For JAVA Script Users
This small but useful piece of code will enable your web site or blog visitors to get to know their IP address. This feature will surely impress a lot of your web site followers.
<script>
<LANGUAGE="JavaScript">
<!– Begin
// This part gets the IP var ip = ‘<!–#echo var="REMOTE_ADDR"–>’;
// This part is for an alert box alert("Your IP address is "+ip); //
End –>
</script>
This piece of script will be prove to be a useful tool to your web site visitors, as people need to know their IP address to play games or share connections.
Place the code within the <HEAD> and </HEAD> of your html document.
If your server pages include xhtml extension, then this code has to be slightly altered. But it works perfectly on html extension. So, as per the set up of your server, you have to re-modify it retaining its soul.
Using the Google AJAX API script
This is the most viable method to track the IP addresses of your web site visitors. This tutorial will enable the web site owner to know the IP address and physical location (like, country) of his web site visitor.
Google offers you a free a way to track the information of your web site visitors. Below is the procedure which is worth trying:
Step 1:
You can sign up for free Google API Key. You can easily load the Google AJAX API script on your web site. This enables Google to record the web site visitors’ information in google.loader.ClientLocation.
<script type="text/javascript" src="http://www.google.com/jsapikey=API_KEY_GOES_HERE"></script>
Step 2:
You have to add this script inside its own <script type="text/javascript"> which would extract the information regarding the web site visitor from google.loader.ClientLocation.
if(google.loader.ClientLocation)
{
visitor_lat = google.loader.ClientLocation.latitude;
visitor_lon = google.loader.ClientLocation.longitude;
visitor_city = google.loader.ClientLocation.address.city;
visitor_region = google.loader.ClientLocation.address.region;
visitor_country = google.loader.ClientLocation.address.country;
visitor_countrycode = google.loader.ClientLocation.address.country_code;
}
else
{
// ClientLocation not found or not populated
// so perform error handling
}
Step 3 :
You have to add up all these scripts to your web page.
The complete coding would look like this :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Get web visitor’s location</title>
<meta name="robots" value="none" />
</head>
<body>
<div id="yourinfo"></div>
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAp04yNttlQq-7b4aZI_jL5hQYPm-xtd00hTQOC0OXpAMO40FHAxQMnH50uBbWoKVHwgpklyirDEregg"></script>
<script type="text/javascript">
if(google.loader.ClientLocation)
{
visitor_lat = google.loader.ClientLocation.latitude;
visitor_lon = google.loader.ClientLocation.longitude;
visitor_city = google.loader.ClientLocation.address.city;
visitor_region = google.loader.ClientLocation.address.region;
visitor_country = google.loader.ClientLocation.address.country;
visitor_countrycode = google.loader.ClientLocation.address.country_code;
document.getElementById(‘yourinfo’).innerHTML = ‘<p>Lat/Lon: ‘ + visitor_lat + ‘ / ‘ + visitor_lon + ‘</p><p>Location: ‘ + visitor_city + ‘, ‘ + visitor_region + ‘, ‘ + visitor_country + ‘ (‘ + visitor_countrycode + ‘)</p>’;
}
else
{
document.getElementById(‘yourinfo’).innerHTML = ‘<p>Whoops!</p>’;
}
</script>
</body>
</html>
And that is all. You can now keep a check on your web site visitors. These are many more methods by which you can trace the information about your website visitors. There are many web tools available online, which enable you to have a look on the statistics of your web site. But ultimately, it is the choice of the web site owner, which varies according to his budget and interest.
These are some of the easy ways to fulfill the same requirement. And it is the time to put these methods into practice.Try them, renovate your web site or blog and trace out your followers.
This is a guest post from Dwarka from Review Unit, which has reviews and latest NEWS about Gadgets, Software, Hardware, Games, Mobile Phones and useful Web Applications. Follow it on Twitter @ReviewUnit & Facebook
It is absolutely right that having your visitors’ IP displayed on your site when they come in adds beauty and enhance your site optimization in someway. In addition to PHP, Java script for launching this on website, I like to share that the HTML code for the same available free with http://www.ip-details.com/
Thanks!! it is good to know about IP address.I also want to know about facebook friend ip location.Is it possible to know about this? If yes then plz tell me appropriate way.
hi!,I love your writing so so much! proportion we be in contact more about your article on AOL? I need a specialist on this house to solve my problem. Maybe that is you! Having a look ahead to peer you.
will this help too?
http://ipaddress-whois.com/my_ip_address