php - how to tell $_GET parameters are equal to or not equal to -
i'm trying make dynamic page $_get vars(params) , have working if var equal something, display content. if var doesn't equal something, either displays content still, or doesn't display error; or displays error , content @ same time
<?php if(!isset($_get['type'])){ header("location: ?type=login"); } else { $type = trim(strip_tags(stripslashes(mysql_real_escape_string($_get['type'])))); } if($type != 'login' || $type != 'register'){ ?> <h1>what looking can't found!</h1> <?php } if($type == 'login'){ ?> <h1>login page:</h1> <?php } if($type == 'register'){ ?> <h1>register page:</h1> <?php }
?>
you have 2 problems in code:
- your check error needs use
&&
, not||
. want see iflogin
andregister
both not used. - you need use
if/else if
statements make sure 1 condition ever present.
check code out:
<?php if(!isset($_get['type'])){ header("location: ?type=login"); } else { $type = trim(strip_tags(stripslashes(mysql_real_escape_string($_get['type'])))); } if($type != 'login' && $type != 'register'){ ?> <h1>what looking can't found!</h1> <?php } else if($type == 'login'){ ?> <h1>login page:</h1> <?php } else if($type == 'register'){ ?> <h1>register page:</h1> <?php }
Comments
Post a Comment