Page 1 of 1
Simple if else wont work
Posted: Sun Mar 20, 2011 2:15 pm
by jpaytoncfd
I have this code:
Code: Select all
if (!empty($_GET['page'])){
$page= "Home";
}else{
$page= $_GET['page'];
}
but even if GET has a value it still goes with the IF
Re: Simple if else wont work
Posted: Sun Mar 20, 2011 2:25 pm
by McInfo
Think about what "not empty" means.
Re: Simple if else wont work
Posted: Sun Mar 20, 2011 2:43 pm
by jpaytoncfd
I'm just learning PHP so I'm not quite sure what you mean. I assume empty is the wrong thing to use?
Re: Simple if else wont work
Posted: Sun Mar 20, 2011 2:55 pm
by Jonah Bron
Here's your code English:
[text]if $_GET['page'] is NOT empty, set $page to home.
if $_GET['page'] IS empty, set that as the page[/text]
Obviously, it's backwards. Remove the exclamation mark. The exclamation mark means "not". You want to go to home if it IS empty.
Re: Simple if else wont work
Posted: Tue Mar 22, 2011 8:32 pm
by gully_mi_seh
by the way this not safe to do it this way because the visitors can modifier the url value so as it for the GET. You should make an array whom content the accepted values, then check if it is a correct value with in_array(). If it is not a element of the array you'll set it up to "home".