Page 1 of 1

IP Address and socket_create()

Posted: Wed Jun 15, 2005 9:33 am
by chvol
How do I determine my IP address within a PHP program?

The program below gets error “undefined function: socket_create()”

However, http://us2.php.net/socket_create says “socket_create (PHP 4 >= 4.1.0, PHP 5)” and phpversion() is 4.3.6

Program Below:
$me=my_ip() ; echo "<br>".$me ;

function my_ip($dest='64.0.0.0', $port=80)
{
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_connect($socket, $dest, $port);
socket_getsockname($socket, $addr, $port);
socket_close($socket);
return $addr;
}

Posted: Wed Jun 15, 2005 9:48 am
by malcolmboston

Code: Select all

$yourIP = $_SERVER['REMOTE_ADDR'];

nope

Posted: Wed Jun 15, 2005 10:11 am
by chvol
That equals 127.0.0.1

http://www.whatismyip.com/ displays something quite different for me.

Posted: Wed Jun 15, 2005 11:20 am
by phpScott
are you running the script on your computer or on a hosted site?

if locally then it will always be 127.0.0.1 unless you change what the localhost server address is.