HaLo2FrEeEk Posted February 7, 2008 Share Posted February 7, 2008 Hey guys, long time no post, I know, but I need some help. This is just the start of my project, basically what I need to do is pass a REQUEST variable to the page, which is then compared to all the values in an array of allow strings. What I'm doing now is this: <?php $cat = $_REQUEST['cat']; // To get the category $allow = array('anime', 'bollywood', 'cartoons', 'comedy', 'documentaries', 'foreign_sub', 'foreign_dub', 'movies', 'music', 'sport', 'tv'); // The list of acceptable values foreach($allow AS $allowcat) { if($cat != $allowcat) { // if the category passed isn't equal to the current iteration of the array... die('Please do not try to break the system, I\'ve set it up nice and neat for you. '.ucfirst($cat).' is not a valid category.'); // ...then die. (here's the problem) } else { echo $cat; // Just a confirmation that it was accepted } } ?> The thing is, where it notes the problem, I can see what's happening, it's killing the script right after the first values doesn't match. What I need is a system that will go through and check each one, and at the end if none matched, then die, otherwise, continue. I can't figure out how to make it happen, could I get some help please? Quote Link to comment https://forums.phpfreaks.com/topic/89872-solved-comparing-array-values-to-a-request-variable/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 7, 2008 Share Posted February 7, 2008 Use this function - http://php.net/in_array Quote Link to comment https://forums.phpfreaks.com/topic/89872-solved-comparing-array-values-to-a-request-variable/#findComment-460594 Share on other sites More sharing options...
HaLo2FrEeEk Posted February 7, 2008 Author Share Posted February 7, 2008 Oh, nice, so basically this: <?php $cat = $_REQUEST['cat']; // To get the category $allow = array('anime', 'bollywood', 'cartoons', 'comedy', 'documentaries', 'foreign_sub', 'foreign_dub', 'movies', 'music', 'sport', 'tv'); // The list of acceptable values if(!in_array($cat, $allow) { die('blah'); } ?> Then go on with my code. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/89872-solved-comparing-array-values-to-a-request-variable/#findComment-460687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.