# \[PHP\] simplify conditional statement

**URL:** <https://forum.kirupa.com/t/php-simplify-conditional-statement/72038>\
**Category:** programming\
**Created:** [December 1, 2004, 6:51pm UTC](https://forum.kirupa.com/t/php-simplify-conditional-statement/72038 "2004-12-01T18:51:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iso\_9000](https://avatars.discourse-cdn.com/v4/letter/i/9f8e36/32.png) [@iso\_9000](https://forum.kirupa.com/u/iso_9000)\
**Post date:** [December 1, 2004, 6:51pm UTC](https://forum.kirupa.com/t/php-simplify-conditional-statement/72038/1 "2004-12-01T18:51:23Z")

</div>

hi… i’ve got a site whose content depends on the value of a parameter in the URL. for example:

[font=Courier New][www.example.com/?section=contact](http://www.example.com/?section=contact)[/font]

i want to prevent someone from manually entering a section that doesn’t exist, by checking the $section variable in the URL against a list of valid categories. if the value entered is not in the list, i want $section to equal “index” so that they will simply go to the home page. i tried this:

[font=Courier New]if ($section != “index”, “contact”, “photos”) {  
$section = “index”;  
}  
[font=Verdana]  
but it doesn’t work. is there a better way to do this than listing each section manually? i actually have quite a few categories, not just the three listed here, so i don’t want to have this giant conditional statement. however, the only way i CAN think of to solve this problem is to make a giant conditional statement, like this:[/font]

[/font][font=Courier New]if (($section != “index”) || [/font][font=Courier New]($section != “contact”) || [/font][font=Courier New]($section != “photos”)) [/font][font=Courier New] {  
$section = “index”;  
}

[font=Verdana]it seems like a kludgy way to do it, but i’m not sure how else to write it. anyone have a simpler solution?[/font]  
[/font]
