How to retrieve web server ip

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
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

How to retrieve web server ip

Post by hedge »

I was using $_SERVER['LOCAL_ADDR'] to determine the IP of the webserver. This works fine if run from an 'external browser' but when the browser is run from the web server it gives me 127.0.0.1...

I have used phinfo to look at all the server vars, they are all set to 127.0.0.1, I was hoping maybe there was a constant set by php or some other method.

this is win2k/IIS/php4.3.1



Does anyone have an idea how I can get the actual IP when I run from the server.

Thanks.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Any website has to have a constant IP: once you know what it is just create a user-defined constant in a config.php file or somewhere?
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

McGruff wrote:Any website has to have a constant IP: once you know what it is just create a user-defined constant in a config.php file or somewhere?
yeah, it looks like that's what I will have to do. The issue is that we have multiple web servers behind a load-balancer. Up to this point I have been able to have exactly the same code on all servers, now I need to have something special on each server.
Post Reply