Jump to content

[SOLVED] Comparing array values to a REQUEST[] variable


HaLo2FrEeEk

Recommended Posts

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.