IP Address and socket_create()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chvol
Forum Newbie
Posts: 20
Joined: Fri Apr 26, 2002 2:49 pm

IP Address and socket_create()

Post 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;
}
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

$yourIP = $_SERVER['REMOTE_ADDR'];
chvol
Forum Newbie
Posts: 20
Joined: Fri Apr 26, 2002 2:49 pm

nope

Post by chvol »

That equals 127.0.0.1

http://www.whatismyip.com/ displays something quite different for me.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
Post Reply