Page 1 of 1

IP of the server

Posted: Fri Jan 30, 2004 4:57 pm
by vijayanand16
How to get the ip address of the server from the PHP code

Posted: Fri Jan 30, 2004 5:40 pm
by Straterra
You could just open a socket and retrieve the information from http://www.whatismyip.com and then parse through that information to get your IP.

Posted: Fri Jan 30, 2004 5:48 pm
by vijayanand16
How i get to know the server name?

Posted: Fri Jan 30, 2004 5:49 pm
by pickle
A MUCH MUCH easier method is to use the built in $_SERVER array.

$_SERVER[SERVER_ADDR] should get you what you need. Check the PHP manual at: http://ca.php.net/reserved.variables for more info.

Posted: Fri Jan 30, 2004 5:53 pm
by vijayanand16
I need IP of the server , not the client's IP

Posted: Fri Jan 30, 2004 6:04 pm
by pickle
Ya, I know. $_SERVER[SERVER_ADDR] will get you the server address. $_SERVER[REMOTE_ADDR] will get you the client's ip. Run this command in a PHP page and you'll see what I mean: "print_r($_SERVER);". That will dump $_SERVER to your browser.

Posted: Fri Jan 30, 2004 6:05 pm
by Straterra
I looked on that page, but couldn't find the array for it. And, in my opinion, the only actual way to find your external IP, is for another machine to tell you what it is.

Posted: Fri Jan 30, 2004 6:11 pm
by pickle
My fault. That particular index (SERVER_ADDR) is not listed on the page I mentioned. However, when you print out the server vars, you WILL see it. I don't know what else to say. The only problems I can see is if you're running PHP from the command line, or if for some reason, your server doesn't create certain variables. Beyond that, it's there.

Posted: Sat Jan 31, 2004 10:25 am
by twigletmac
Check what's in the $_SERVER array by doing:

Code: Select all

echo '<pre>';
print_r($_SERVER);
echo '</pre>';
Mac

Posted: Mon Feb 02, 2004 11:30 am
by vijayanand16
Thanks