Page 1 of 1
Ipaddress detetction through code
Posted: Thu May 14, 2009 5:05 am
by s_coder
Hello ,
i need the ipaddress of the local computer but when i find the ipaddress online i get the ipaddress of the router. is there any function in php where i can find my local computer ipaddress? i used echo $ip = $_SERVER['REMOTE_ADDR'];
$ip=$_SERVER['HTTP_CLIENT_IP']; but i am not getting the ipaddress of the local computer.

Re: Ipaddress detetction through code
Posted: Thu May 14, 2009 5:21 am
by Yossarian
The items available to you can be seen by looking at the output of ;
.. in the various places you are testing from.
Re: Ipaddress detetction through code
Posted: Thu May 14, 2009 6:19 am
by s_coder
hello
i did what u said but still it is not showing the ipaddress of my local computer.
Re: Ipaddress detetction through code
Posted: Thu May 14, 2009 8:14 am
by Yossarian
When you say "local computer" do you mean;
the machine you are sitting at, a dev machine with a webserver
OR
a server on your local network, probably an intranet
This is the output from my local machine, the computer I am sitting at, when I access it as localhost or 127.0.0.1.
Code: Select all
'SERVER_SOFTWARE' => string 'Apache/2.0.63 (Win32) PHP/5.2.6' (length=31)
'SERVER_NAME' => string 'code' (length=4)
'SERVER_ADDR' => string '127.0.0.1' (length=9)
'SERVER_PORT' => string '80' (length=2)
'REMOTE_ADDR' => string '127.0.0.1' (length=9)
'DOCUMENT_ROOT' => string 'C:/var/www/html/code' (length=20)
Re: Ipaddress detetction through code
Posted: Thu May 14, 2009 8:25 am
by s_coder
Using $_SERVER['REMOTE_ADDR'] i am geting the ip address of the router.
Whereas I want the IP address of the Local machine because I want to detect that particular client based on that IP Address
Re: Ipaddress detetction through code
Posted: Thu May 14, 2009 8:28 am
by crazycoders
You cannot get the ip adresse of a NATed machine. When behind a router, the ip adresse is going through something called a NATting process that hides the different implementations of the calling computer and at the same time allowing the user to have the same IP as someone else on his network but only at the web level not internally.
When you receive the request, you receive it just like it was a normal user but it is the router instead that is contacting you, not the client's computer.
So, in conclusion, no, there is no way to get the ip of the computer sending a request through PHP. You can maybe do it with a local pluggin, activex control or even flash maybe, but you can't do it from PHP...