Ipaddress detetction through code

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
s_coder
Forum Newbie
Posts: 8
Joined: Thu May 14, 2009 4:59 am

Ipaddress detetction through code

Post 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. :(
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: Ipaddress detetction through code

Post by Yossarian »

The items available to you can be seen by looking at the output of ;

Code: Select all

var_dump( $_SERVER );
.. in the various places you are testing from.
s_coder
Forum Newbie
Posts: 8
Joined: Thu May 14, 2009 4:59 am

Re: Ipaddress detetction through code

Post by s_coder »

hello
i did what u said but still it is not showing the ipaddress of my local computer.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: Ipaddress detetction through code

Post 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)
 
s_coder
Forum Newbie
Posts: 8
Joined: Thu May 14, 2009 4:59 am

Re: Ipaddress detetction through code

Post 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
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: Ipaddress detetction through code

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