Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to write a php if else statement along the lines of:

if ($_SERVER['SERVER_NAME'] = local ) {

Content here should display if the current url is for example,

} elseif ($_SERVER['SERVER_NAME'] = stage)

Content here should display if the current url is for example,

} else {

Content here should display if the current url is for example,


I'm assuming ($_SERVER['SERVER_NAME'] = local ) and ($_SERVER['SERVER_NAME'] = stage) isn't right so hopefully someone knows the exact syntax. Thanks!

share|improve this question

closed as off topic by Ladadadada, Michael Hampton, mdpc, Chopper3, Iain Oct 23 '12 at 20:33

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Your question is off topic for Serverfault because it appears to relate programming. It may be on topic for StackOverflow but please search their site for similar questions that may already have the answer you're looking for. – Iain Oct 23 '12 at 20:33

You can do it with a switch statement and use the default case to do that :-)

I'm not sure if you did that on purpose but you need a double "equal" sign to test the value and you also need to put your value between quotes :

if ($_SERVER['SERVER_NAME'] == 'local' ) {....
share|improve this answer
Great, I'll add the extra = and the quotes. Thanks! – cchiera Oct 23 '12 at 15:18
Actually, it seems that doesn't quite work. If I change local to it works but it doesn't if it's just local. – cchiera Oct 23 '12 at 15:23
That's normal, the values must be exactly the same! You can write a regular expression to detect that have a look on – DJYod Oct 23 '12 at 19:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.