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

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
amer82
Forum Newbie
Posts: 1
Joined: Thu Feb 19, 2009 11:42 pm

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

Post 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.
p3rk5
Forum Commoner
Posts: 34
Joined: Thu Jan 29, 2009 10:19 pm

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

Post by p3rk5 »

I don't think this is possible with PHP. Try Java, http://www.xelon.it/articles/find-local-IP-java-nat/
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post by Weirdan »

$_SERVER['REMOTE_ADDR'] will give you user ip she is connecting from.
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

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

Post 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
p3rk5
Forum Commoner
Posts: 34
Joined: Thu Jan 29, 2009 10:19 pm

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

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply