It is normal practice for website owners to track the IP addresses of visitors to their sites. Every sort of Internet communication, including posts, pages, and media, necessitates the use of an Internet Protocol (IP) address in order to display the required response to the relevant query. Using various tools and plugins, you can quickly track your website’s IP address.

In this article, I will explain to you how to track IP address of website visitors with PHP code and IP address tracking plugins. IP addresses help you to enhance content marketing based on the geographical location of visitors. Also, you will be able to track the bad IP address which harms your website including security threats.

Unfortunately, due to privacy and security concerns,  Google Analytics wouldn’t allow tracking visitor IP addresses. But there are other different methods of tracking the IP address of website visitors which I am going to discuss. Also, learn How to prevent cross-site tracking on any device.

What Is IP Address?

how to track IP address of website visitors

An IP address is a unique address that differentiates one device from another one on the web or in a connection. Your device’s IP address is the unique id that allows it to transmit and receive information packets over the internet.

It stores information such as location, allowing two-way transmission of data. An IP address is in the form of numeric numbers which are segregated by the decimals (.) like 192.168.1.5. In 1998, a new edition of IP (IPv6) was established, containing 128 bits for the IP address, due to the digital revolution and the expiration of existing IPv4 addresses.

IP addresses could be private and public which are entertained by individual and public devices or networks, respectively. Learn how to allow a website through the firewall in easy steps.

How To Track IP Address Of Website Visitors Using PHP?

PHP retains a list of client and networking parameters in an unsorted array named SERVER. The best way to track website visitors is using the PHP code in your hosting in the following manner:

$ipaddress = $_SERVER['REMOTE_ADDR'];

This IP address is commonly connected to the gethostbyaddr() function to determine the hostname concerned with the stipulated IP address, which can be used in the following ways:

$hostname = gethostbyaddr($ip);

That’s it. Now the connected hostname and sever file will be connected with the records of your website’s database. You can track every single visitor’s IP address especially if you are using Google analytics. As I discussed above, analytics won’t allow tracking visitors of a website due to privacy concerns then this method will be quite useful.

If the above code doesn’t work and if you are unable to get the real IP addresses of website visitors then try this one code:

function getUserIP() {
if( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')>0) {
$addr = explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($addr[0]);
} else {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
else {
return $_SERVER['REMOTE_ADDR'];
}
}

Use the above code with:

$ip = getRealUserIp();

Remember, these two codes are sufficient enough to get the real IP address of the client but any of them doesn’t guarantee to get a real IP address. Because it is quite prevalent for website visitors to disguise their real IP addresses and use the internet anonymously.

How To Track IP Address Of Website Visitors Using Plugin?

Plugins are, without a doubt, the ultimate answer for any challenge with WordPress as well as other CMS, and I always encourage installing plugins to save time. There are several plugins that can assist you to track IP address of a visitor on website.

How To Track IP Address Of Website Visitors Using Plugin

After researching and personal experience, I found TraceMyIP is the best plugin for newbies and established websites as well. TraceMyIP is the best plugin for tracking IP address of website visitors and comes with tracking, surveillance, website statistics, and analytics service.

Step 1. Install And Setup TraceMyIP

You can easily download and install it on your CMS dashboard.

  • If you are using WordPress, go to your plugin directory.
  • Search TraceMyIP on the search bar.
  • Install and activate the plugin.

track ip address

Step 2. Get The Tracking Code

  • After installation, sign up for a free account using credentials.

How To Track IP Address Of Website Visitors

  • Follow the instructions that it asks including what you want to track, how to capture visitors, email notifications, visitors alerts, etc.
  • Once, all the instructions are filled, and the setting is completed, it leads you to the new page where you will get the Tracking Code.

Step 3. Paste Tracking To The Theme

This is the final step where you have to paste the above visitor tracking code into your website theme editor or HTML. I’m discussing here how to do this with WordPress, you can implement it on other CMS too.

  • Go to your WordPress (or other CMS) dashboard.
  • Click on the Appearance and then Theme File Editor; Appearance >> Theme File Editor.

how to track website visitors

  • On the right side, select and click on the header.php which opens header files on the theme editor.
  • Paste the generated code at the bottom of the file and click on the update file button.

That’s it. If you followed the above instructions carefully, TraceMyIP starts tracking website visitors’ IP addresses. You can find all the information at the My Projects inside the plugin dashboard.

How To Find IP Address Of Any Website?

This is somewhat different from how to track IP address of website visitors because here you will find the IP addresses of the website, not the visitors. It is very simple to use where you just need to use a command prompt.

If you are using windows devices then press the Window and R key simultaneously to find the IP address of any website; Window+R. In the command prompt type “tracert” and then the website URL after space (don’t use commas!).

How To Track IP Address Of Website Visitors

For example – If I wish to find the IP address of my website then it would be: tracert www.basicwebguide.com and then click on the OK button or press enter. The first line of the command displays your website name and IP address in front of this as shown in the above screenshot.

Final Thoughts

It is all about how to track IP address of website visitors and I hope you like this article. We comprehensively discussed various methods to track visitor’s IP address with the PHP codes and with the help of the TraceMyIP plugin.

I again want to remind you, although these are the best possible solutions to track the IP address of website visitors yet they may not track all addresses. As I stated, there is a large possibility that whether users browsing your site anonymously or conceal their IP addresses. In these scenarios, you may not able to get a real IP address.

This Post Has One Comment

Leave a Reply