abdfahim Posted November 21, 2007 Share Posted November 21, 2007 I think this is pretty simple ... I know that I can get user IP by echo $_SERVER['REMOTE_ADDR']; But how can I display server IP (The IP user needs to enter on the address bar of the browser to access the website. ..... I know the question is wired but believe me I need it. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 21, 2007 Share Posted November 21, 2007 $_SERVER['HTTP_HOST'] PhREEEK Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 21, 2007 Share Posted November 21, 2007 this should work echo $_SERVER['SERVER_ADDR']; Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 21, 2007 Share Posted November 21, 2007 <?php echo $_SERVER['SERVER_ADDR']; ?> rajivgonsalves beat me to it Quote Link to comment Share on other sites More sharing options...
prime Posted November 21, 2007 Share Posted November 21, 2007 try this <?php $server_ip = "$_SERVER['SERVER_ADDR']"; echo "$server_ip"; ?> Quote Link to comment Share on other sites More sharing options...
abdfahim Posted November 21, 2007 Author Share Posted November 21, 2007 I have tried that. But the problem is it returns 127.0.0.1, which is the address of localhost, u know. But I want to know the external IP that is used by the visitors to visit the server page. Quote Link to comment Share on other sites More sharing options...
abdfahim Posted November 21, 2007 Author Share Posted November 21, 2007 wait .. I think I am making u confused ... I am trying to explain it more ... let my server's IP is 150.160.170.180 ... When i use the code echo $_SERVER['SERVER_ADDR']; in a php page, any visitor visits my page will see this IP address - 150.160.170.180. But if I visit my page from the server itself from localhost, it will definite show 127.0.0.1. But I need to show the external IP of my server page, as my server has a dynamic IP address, so that anyone can just come to the server and note its current IP in case the IP had changed. By the way, its a small home network. Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 21, 2007 Share Posted November 21, 2007 because you run your script in localhost.. local host is 127.0.0.1 Quote Link to comment Share on other sites More sharing options...
abdfahim Posted November 21, 2007 Author Share Posted November 21, 2007 yup I know .. But I am checking whether I can show the external IP address from running the script in localhost (just like some softwares do, show IP address) .. Quote Link to comment 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.