Page 1 of 1

Want a function for two IP's one real one local

Posted: Fri Feb 20, 2009 12:51 am
by amer82
Dear Sirs,

I have a site for a company. And this company has real Ip's and exchange server.

One of the real IP's is for the exchange server then we can access it from outsite the company, and the link for it is on the site.

The problem is we cann't access the link from inside the company because we cann't use the real IP's from inside the company and we are using them for our internet connection.

I need a function to be used for this case:

If the user want to access the link for the exchange from inside the company the link should takes him to the local IP for the exchange (example : https://192.168.100.1/owa), and if the user want to access the link for the exchange from outside the company the link should takes him to the real IP for the exchange (example: https://77.225.125.81/owa) .

Then the function should read the local user IP to see if it from inside or outside the company.

Thank you a lot,
Best Regards.

Re: Want a function for two IP's one real one local

Posted: Fri Feb 20, 2009 1:24 am
by p3rk5
I don't think this is possible with PHP. Try Java, http://www.xelon.it/articles/find-local-IP-java-nat/

Re: Want a function for two IP's one real one local

Posted: Fri Feb 20, 2009 3:55 am
by Weirdan
$_SERVER['REMOTE_ADDR'] will give you user ip she is connecting from.

Re: Want a function for two IP's one real one local

Posted: Fri Feb 20, 2009 4:12 am
by pcoder
It depends upon your network configuration.
We have three server variables to get the client's IP called REMOTE_ADDR,HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR.
First of all try to get the IP Address of client's machine, if not go for the forwarded address and then only go for the remote address.
Cheers

Re: Want a function for two IP's one real one local

Posted: Fri Feb 20, 2009 11:44 am
by p3rk5
The x-forwarded-for header is not a standard http header (hence the x-prefix). It is an attempt by the big proxy server vendors to help ISP's identify and block abusive IP addresses.

If there are two proxy servers between the client and your server you will see two IP addresses in the x-forwarded-for header, the clients and one of the proxy servers. As the requests moves through a proxy server the IP address of requester is append to the x-forwarded-for header. Hence the first IP address will be the original client IP and there can be any number of IP addresses depending on how many proxy servers it passes through.

Re: Want a function for two IP's one real one local

Posted: Fri Feb 20, 2009 4:49 pm
by VladSun
I think the best solution will be to use BIND views feature and to use domain name instead of IPs (that's what domain names were created for ;) ). This way your DNS will resolve the public address of the server when the client IP is public and the private IP of the server when the client IP is from your private subnet.

PS: You should use "public" and "private" IP address instead of "real" and "local". While I'm very familiar with the usage of "real IP" it's not so with other people.