|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Get Local IP adress using PHP
Dear All,
Is it possible to get a local IP (behind a firewall/proxy server) using php / javascript? Thank you in advance for your help. |
|
#2
|
||||
|
||||
|
Do you mean local IP as in the remote client's IP?
$_SERVER['REMOTE_ADDR'] The IP address from which the user is viewing the current page. Check the php documentation for more information: http://ca2.php.net/reserved.variables |
|
#3
|
|||
|
|||
|
Quote:
Not properly! $_SERVER['REMOTE_ADDR'] will indeed give me de IP from which the user is viewing the page but what I realy like to know is as follows: If the user is part of a local network that uses a proxy server to access the internet it will have a local IP to acess that proxy. The problem is that I need to recognize one single computer in that local network but not all the computers behind that proxy. Thank you for your help. |
|
#4
|
||||
|
||||
|
Do you want to share with us why you need some sort of IP? It smells...
|
|
#5
|
|||
|
|||
|
Quote:
Yes, no problem! I have an on-line service to libraries that I would like to provide to single computers after a subscription. I initialy though about using an ip adress autentication in order to avoid two problems with user name/pass autentication: 1- The library needs to ask for the password every time e wants to access the service. 2- Avoid the pass distribution to other people. Thanks, I really hope it doesn't suck's... If you have another solution please advise... |
|
#6
|
||||
|
||||
|
Ok, I understand... Sorry for that!
I know that people can look at their local adress, and I know that there are some online functions for that... Have you tried Javascript yet? |
|
#7
|
|||
|
|||
|
Quote:
I found something using js and asp but I'm quite new in php and I couldn't get it work... ![]() |
|
#8
|
||||
|
||||
|
If it works in ASP it'll definitely work in PHP! I don't have much experience using js with PHP, but you'll figure it out.
Maybe you'll find something here |
|
#9
|
||||
|
||||
|
Not neccesarily
Not everything is cross platform.. I know that you can get the IP address of the person visiting, the address assigned to them, however if they are behind a firewall or router the capability of getting that internal address is much harder. I would think that you would have to open a direct connection client side to your server in order to get an internal ip address.. and for the type of security you are trying to impliment, ip address authentication would be a bad idea -- addresses can be faked. For example, if I knew that I could establish a connection to your machine via a specific method (for example secure connection thru ssh) and you didn't have any limit on to how many ip addresses I could submit, ideally I could find out your internal ip structure by process of elimination (most people who have home lans use the default of 192.168.x.x with a subnet of 255.255.255.x as default) and therefore fake a packet and get the files you're hosting.. You might want to think about another method for this ![]() Quote:
|
|
#10
|
|||
|
|||
|
I know that many people use the default 192.168.x.x with a subnet of 255.255.255.x. However I could use both, the server ip and then the lan-network ip to cross check. But any way I will use another sort of validation..
Thank u all |
|
#11
|
|||
|
|||
|
get local IP with php
Hi all,
That's a little late, but that may help other people, if you want to get the local IP of the user in the situation where the user is requesting through a proxy : $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'] should do the trick... |
|
#12
|
|||
|
|||
|
I tried:
$HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'] But it return an empty value. What else do I have to do to get the correct output? I am using PHP 4.3.X |
|
#13
|
|||
|
|||
|
Depends on proxy
Whether $_SERVER['HTTP_X_FORWARDED_FOR'] is set or not depends on the proxy server. Not all proxy servers will set this value, so that is why it does not always appear.
You can enable or disable forward reporting in most proxy servers, and the smart move is to disable it; after all, you don't want people on the Internet knowing about the structure of your internal LAN! ![]() |
|
#14
|
|||
|
|||
|
Yup, should not be a problem. Their internal IP and more, but the catch is that it has to be IE.
Take a look at Patch Management for an example. I think it does have something with x_forwarded_for and perhaps it is spelled dirrerent - like the referer and the referrer, just depends on the browser being used. URL Quote:
|
|
#15
|
|||
|
|||
|
Look for HTTP_FORWARDED_FOR. It should be inside your CGI variable. But again it is not guranteed that it will always be available as it depends on the proxy server thur which the client machine is accessing the internet. So proxy servers do send the HTTP_FORWARDED_FOR and some do not.
|
|
#16
|
|||
|
|||
|
Is it possible to get a local IP Address
Use the following function
<?php function getIp() { $ip_address=$_SERVER['HTTP_X_FORWARDED_FOR']; if ($ip_address==NULL){ $ip_address=$_SERVER[REMOTE_ADDR]; } return $ip_address; } Last edited by jayesh : November 24th, 2004 at 05:16 AM. Reason: update |
|
#17
|
|||
|
|||
|
Hi ... please check the jayesh 's code It probably would work for you.
here's a little tip in case you are missing it, don't check the script in your local lan. proxy's are normally configured to bypass local lan's so put your code on some remote server and then try it out. http://www.asifiqbal.com/img.php check this link it works perfect for me using firefox, ie, netscape. I am behind squid proxy. I am not sure about the other proxies. Asif Quote:
|