location based if statement

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
ph33rful
Forum Newbie
Posts: 1
Joined: Sat Feb 21, 2004 12:14 am

location based if statement

Post by ph33rful »

i dont even know if the subject makes sense.

how would i make php write out one line of text if the location (the browser location) is somewhere (say: http://127.0.0.1) and print out something else if the location is somewhere different (say: domain.com)

im sure it would be something like:
if
location = http://127.0.0.1
echo "localhost"
elseif
location = http://domain.com
echo "away from home"
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Code: Select all

<?php

if($_SERVER['SERVER_NAME'] == "localhost"){

        echo "localhost";

}else{

        echo "away from home";

}

?>
This should work. :D
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

I think you would rather use $_SERVER['REMOTE_HOST'] or $_SERVER['REMOTE_ADDR'] if you are trying to get client information. If you want server information then you would use $_SERVER['SERVER_NAME']
Post Reply