I am trying to write a code to get IP of a computer.
I have written the following code :
<?php
$ip=@$REMOTE_ADDR;
echo "<font face='Verdana' size='3'><b>IP Address= $ip</b>";
?>
But the output I am getting is :
IP Address= 127.0.0.1
i.e the common IP for all machines, what is the code to get the actual IP of a machine such as 192.163.0.9?
Please help..
Thank you.

Recommended Answers

All 6 Replies

$_SERVER is used to get the IP address of a client.

More about it Here

$_SERVER is used to get the IP address of a client.

More about it Here

I have also tried $_SERVER but it is giving the same output..

well, thats because, you are probably testing it locally, like, http://localhost/ip.php and most probably, while configuring apache, you have given IP as 127.0.0.1 (or localhost). Try putting it on a server and check. It will work. :)

Are you behind some proxy ?

I am trying to write a code to get IP of a computer.
I have written the following code :
<?php
$ip=@$REMOTE_ADDR;
echo "<font face='Verdana' size='3'><b>IP Address= $ip</b>";
?>
But the output I am getting is :
IP Address= 127.0.0.1
i.e the common IP for all machines, what is the code to get the actual IP of a machine such as 192.163.0.9?
Please help..
Thank you.

Try using one of these: $ip = getenv('REMOTE_ADDR'); --or-- $ip = $REMOTE_ADDR;

no matter what you use, if you are testing it locally, you will get 127.0.0.1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.