Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.