$_SERVER problem

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
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

$_SERVER problem

Post by softsolvers »

Hello friends,
I am unable to find the ip address of the server,i am using following code.
<?php
echo $_SERVER['SERVER_ADDR'];
?>
But i am unable to see the address, i have register_global=on in my php.ini file is it make any problem .In a project i have to put register_global to on ,now how can i view the ip address of the server.
Plz. suggest me
Softsolvers
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Try $_SERVER["REMOTE_ADDR"];
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

its

Code: Select all

$_SERVER&#1111;"HTTP_HOST"];
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

evilcoder wrote:its

Code: Select all

$_SERVER&#1111;"HTTP_HOST"];
No evilcoder it is not. HTTP_HOST wil echo out the host. Like google.com or forums.devnetwork.net
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

you might want to try:

Code: Select all

echo getenv("SERVER_ADDR");
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

Try:

Code: Select all

print '<pre>';
print_r($_SERVER);
Among others; you'll see:

Code: Select all

$_SERVER['SERVER_ADDR']
I believe it is undocumented.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

yeah your right penquinboy. Even if you do phpinfo() it will come up with a list of all the $_SERVER vars, and yes $_SERVER['SERVER_ADDR'] is on there!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What's available in the $_SERVER array is governed by the server - not all elements will be available on all servers, best thing to do is what penguinboy suggested -

Code: Select all

echo '<pre>';
print_r($_SERVER);
echo '</pre>';
that way you can see what's available on your server and can find the information you are looking for.

Mac
Post Reply