Jump to content

Recommended Posts

how do i wrote a streamline code to make a $_GET['value'] only have certain values. For instance if $_GET['value'] is NOT equal to either 'music', 'sports','random','whatever' send user elsewhere?

 

I'm going to use this value in a form as a default for a selection list. And i wanna make sure the variable is listed as an option.

Link to comment
https://forums.phpfreaks.com/topic/168872-variable-can-only-have-certain-values/
Share on other sites

people can just type things in the URL to make it whatever they want so you have to work from it after that...

 

$value = $_GET['value'];

if ($value != "music" && $value != "sports" ...etc...)

  $value = "music";

//or whatever you want it to equal if it is not valid

If your variable can only contain certain values then setup an array of possible values.

$accepted_values = array('value1', 'value2', 'value3', etc);

// now see if $_GET['value'] contains a value that is accepted
if(in_array($_GET['value'], $accepted_values))
{
    // $_GET['value'] holds an accepted value
}

 

You can ofcourse go the other way and setup an array of non accepted values

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.