PHP Syntax Question


What I am trying to do is this:

if server name = or
Display this

How can I do that?
if ($_SERVER['SERVER_NAME'] ==  ""){

Open in new window

Computer GuyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

given this:
$_SERVER['SERVER_NAME'] will report only ''

the "/test" can be obtained from $_SERVER['REQUEST_URI'].

As for the 'x' OR 'y', the "OR" is expressed using "||" (without the quotes):

if( ''==$_SERVER['SERVER_NAME'] || '/test'==$_SERVER['REQUEST_URI']) )
Ray PaseurCommented:
Maybe like this...

if ( ($url == '') || ($url == '') )

You can find some of these PHP variables by running the script in the code snippet.
<?php phpinfo();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NOTE: due to "if server name = or
Display this"
if the url is actually

the "Display this" part will always execute because you are already allowing it to do so based on "" alone. In other words, the "OR" part will be ignored because "" is evaluated first and since it evaluates to true, the "Display this" part will execute.  In other words (based on the way you described/phrased your problem), this would suffice:
if( ''==$_SERVER['SERVER_NAME'] )
  echo 'Display this';

If you actually want to "Display this" only if the url is "" (or a variant of it -,, then what you need is:

if( preg_match('$#i',($_SERVER['SERVER_NAME'].['REQUEST_URI']) ) )
  echo 'Display this';
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.