Page 1 of 1

location based if statement

Posted: Sat Feb 21, 2004 12:14 am
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"

Posted: Sat Feb 21, 2004 12:27 am
by Drachlen

Code: Select all

<?php

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

        echo "localhost";

}else{

        echo "away from home";

}

?>
This should work. :D

Posted: Sat Feb 21, 2004 11:35 am
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']