Jump to content

Is there a way to display local IP address using php?


dlebowski

Recommended Posts

Hi.  I wanted to know if there is a way in php (i haven't had any luck finding a way) to display the users LOCAL ip address?  I want to do this because the user using my application will be hosting apache on their machine. If another machine on their network wanted to use the application, they would need to know what ip to browse to.

 

For example:

 

your ip is:  192.168.1.51

Link to comment
Share on other sites

Thanks for the reply.  I have never gotten this to work.  I am using xampp for my web server and this is what my code looks like:

 

<?php    

    echo    $ip = $_SERVER["REMOTE_ADDR"];
        
   
?>

 

Here is the result:

 

::1

Link to comment
Share on other sites

$_SERVER['REMOTE_ADDR'];

 

Does not show the local IP-address (unless your surfing on intranet). If your surfing on the internet it will show the IP assigned to you by your ISP. It can also show a made-up IP-address (like 0.0.0.0 equals all IP-addresses on the internet).

 

The point is, you can't.

Link to comment
Share on other sites

PHP is a server-side language, it communicates with clients via requests and responses.

Since (most likely) no browsers support the ability to provide the local ip address in response to any tcp request, you would need to run a script capable of retrieving the local ip on the client machine.

 

Java is the most obvious since (mostly) everyone has it installed and ready.

 

-cb-

Link to comment
Share on other sites

PHP is a server-side language, it communicates with clients via requests and responses.

Since (most likely) no browsers support the ability to provide the local ip address in response to any tcp request, you would need to run a script capable of retrieving the local ip on the client machine.

 

Java is the most obvious since (mostly) everyone has it installed and ready.

 

-cb-

 

Apparently they use Java as my JVM started to boot

Link to comment
Share on other sites

Java is the most obvious since (mostly) everyone has it installed and ready.

Except most if not all shared servers :)

? Java is client based, so servers dont need java to be installed at all. Only the clients machine needs the JVM Runtime. And javascript is built into most browsers.

 

I think he did mean -local- ip address, rather than public.

 

Hi.  I wanted to know if there is a way in php (i haven't had any luck finding a way) to display the users LOCAL ip address?  I want to do this because the user using my application will be hosting apache on their machine. If another machine on their network wanted to use the application, they would need to know what ip to browse to.

 

For example:

 

your ip is:  192.168.1.51

 

Your question seems a little confusing:

There is machine 1, That hosts your application, the Apache server, and a client (home pc?)

There is machine 2, That may need to know the ip address of machine 1 locally?

So if they are on the same network they are most likely in the same building in which case its redundant.

 

I dont see why you need this functionality.

-cb-

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.