How To See Visitors Hosts IP Address

How To Receive Visitors Hosts IP Address

Introduction: PHP Discover Host Ip Address

Are you a programmer? Are you interested in some of the obscure workings of PHP? Well if you are, then you will enjoy this tiny blog post. Word press is a very secure platform. As a matter of fact, there are word press security plugins that enforces a lot of good security practices. Our word press plugin for an easy to use, stale and well supported security plugin will sincerely help you in your endeavors.

But, what if you wanted to do something of this nature yourself but from a tiny php program you wrote yourself.

Get Your PHP Hat On

Did you know that PHP can be used to retrieve the IP address of a website visitor and, lets go further to say- what is this good for? The primary use of the is to display the IP address of all visitors, thus making use of the information. PHP has predefined $_SERVER array variables using which IP addresses of both visitors and hosts can be retrieved and saved (for later reporting). The gethostbyaddr() function is thus used to find out the hostname.

The program code REMOTE_ADDR and HTTP_HOST contain the visitor IP address and host IP address. To find out what the IP address of a visitor using PHP use the command $_SERVER[‘REMOTE_ADDR’] variable. For example:

 

<?php

print “Your -IP- address is “.$_SERVER[‘REMOTE_ADDR’];

?>

 

If you want to go ahead and record this IP address insert the value into a database. Your web server’s IP address using PHP uses the $_SERVER[‘HTTP_HOST’] variable. To get the variable use the gethostbyaddr() function with IP address as the parameter. For example:

?php print gethostbyaddr(“127.0.0.1”);

When a hostname cannot be resolved the same IP address is returned. We hope that the explanation of this tiny code has helped you with your endeavor into learning PHP. Learning PHP is not difficult, but it does take dedicating your time and attention to writing PHP code. It was not an accident that we wrote this blog post because we needed to kill two birds with one stone. This post solved one of our problems and being able to share our research with you is a wonderful experience. We hope that you enjoyed it and we have more information should you decide to utilize our software.

More Information

  • Secure Your Website | All In One Security & Firewall
  • WinSCP FTP Secure SFTP Client Product Review
  • Advanced Access Manager
  • How To Make A Bear Metal Backup

You May Also Like

%title%
%price%%time%
%image%
%title%