Finding the Server's 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
Bert
Forum Newbie
Posts: 6
Joined: Sat Dec 07, 2002 12:26 pm
Location: California, USA

Finding the Server's IP

Post by Bert »

Is there a script that I can upload to my webhost and have it tell me my webhost's IP address?
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

You can do better than that!

file: phpinfo.php

Code: Select all

<html>
<body>

<?php

 phpinfo();

?>

</body>
</html>
Upload it to your host and point your browser to the file. PHP will parse it and give you loads of useful information.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

$_SERVER['SERVER_ADDR']

contains the IP of the server.
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

or _ENV['SERVER_ADDR'], or REMOTE_HOST, or REMOTE_ADDR depending on your servers set-up. But you should be able to spot what an IP address looks like!

Call it in your scripts by placing a dollar in front of the variable you decide to use.

(These are reserved, global variables in PHP)
Bert
Forum Newbie
Posts: 6
Joined: Sat Dec 07, 2002 12:26 pm
Location: California, USA

Post by Bert »

None of those worked.

phpinfo(); - didnt give me the ip

$_SERVER['SERVER_ADDR']; - didnt work

$_ENV['SERVER_ADDR']; - didnt work

$REMOTE_HOST; - displayed MY IP

$REMOTE_ADDR; - displayed MY IP

If it matters, I'm using PHP 4.0.0
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

$_SERVER['LOCAL_ADDR']
nieve
Forum Newbie
Posts: 11
Joined: Tue Dec 03, 2002 10:26 pm

Post by nieve »

did you echo it?
<?
echo "$_SERVER[SERVER_ADDR]";
?>
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try

$SERVER_ADDR, or $_HTTP_SERVER_VARS['SERVER_ADDR']
Post Reply