dlebowski Posted April 19, 2010 Share Posted April 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/ Share on other sites More sharing options...
TeddyKiller Posted April 19, 2010 Share Posted April 19, 2010 $_SERVER['REMOTE_ADDR']; Is this what you are looking for. . ? Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1044831 Share on other sites More sharing options...
dlebowski Posted April 19, 2010 Author Share Posted April 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1044840 Share on other sites More sharing options...
TeddyKiller Posted April 19, 2010 Share Posted April 19, 2010 It's think its suppose to. ::1 is equivalent to your ip address. It's probably the way xampp is setup. It's the code I use, and it works. Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1044843 Share on other sites More sharing options...
ignace Posted April 19, 2010 Share Posted April 19, 2010 $_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. Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1044862 Share on other sites More sharing options...
dlebowski Posted April 20, 2010 Author Share Posted April 20, 2010 These guys do it, but they are doing it with javascript. I still cant do it despite looking at their code. browserspy.dk/ip.php Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1045026 Share on other sites More sharing options...
ChemicalBliss Posted April 20, 2010 Share Posted April 20, 2010 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- Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1045029 Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1045105 Share on other sites More sharing options...
TeddyKiller Posted April 20, 2010 Share Posted April 20, 2010 Java is the most obvious since (mostly) everyone has it installed and ready. Except most if not all shared servers Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1045107 Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 Apparently I misread your question, you can use $_SERVER['REMOTE_ADDR'] if you are browsing locally as mentioned in my previous post (intranet). Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1045120 Share on other sites More sharing options...
ChemicalBliss Posted April 20, 2010 Share Posted April 20, 2010 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- Quote Link to comment https://forums.phpfreaks.com/topic/199054-is-there-a-way-to-display-local-ip-address-using-php/#findComment-1045159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.