MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
January
Sun Mon Tue Wed Thu Fri Sat
         
9
           
2010
Months
Jan


Sat, Jan 09, 2010 9:09 pm

Checking Client IP address with PHP

I noticed that two PHP scripts, BrowserInfo and BrowserTest, that I use to have people provide me with information on their browser, such as the plugins available, were not providing the IP address from which browsers were viewing the scripts, because I hadn't updated them for a long time, but had upgraded PHP on the website quite some time ago. The relevant old code is shown below:
<?php
$IP = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$FQDN = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
print ("<b>IP Address:</b> $IP<br>");
print ("<b>FQDN:</b> $FQDN<br>");
?>

I had to change the code to that shown below:

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$FQDN = gethostbyaddr($_SERVER['REMOTE_ADDR']);
print ("<b>IP Address:</b> $IP<br>");
print ("<b>FQDN:</b> $FQDN<br>");
?>

References:

  1. how to get client's IP address in PHP
    Date: August 10, 2006
    PHPBuilder.com
  2. Predefined Variables
    Last Updated; January 8, 2010
    PHP: Hypertext Preprocessor

[/network/web/browser] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo