Filed Under (PHP Code Samples) by Anoop on May-22-2007
Code (php)

<?php
$URL = 'www.yah.in';
$ip = gethostbyname($URL); // Get IP address from a URL
$out = "The following URLs are equivalent (for dedicated IP addresses only): ";
$out .= $URL.', http://' . $ip . '/ http://' . sprintf("%u", ip2long($ip)) . "";
echo $out;
echo "Your IP address: ".$_SERVER['REMOTE_ADDR'];
?>
 

You can also use long2ip() function to get ip address back from a long code.



Alex Luui on April 19th, 2009 at 10:46 am #

Thank you very much for this.
Really helped a lot.

Rahul Anand on May 27th, 2009 at 9:38 pm #

Thanks. Its really Helpful. Nice code to use

Post a comment
Name: 
Email: 
URL: 
Comments: