dadamssg Posted August 5, 2009 Share Posted August 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/168872-variable-can-only-have-certain-values/ Share on other sites More sharing options...
smerny Posted August 5, 2009 Share Posted August 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168872-variable-can-only-have-certain-values/#findComment-891001 Share on other sites More sharing options...
dadamssg Posted August 5, 2009 Author Share Posted August 5, 2009 right, i wrote a function to clean the data but just wasn't sure the shortest way to check for certain values. thanks Quote Link to comment https://forums.phpfreaks.com/topic/168872-variable-can-only-have-certain-values/#findComment-891004 Share on other sites More sharing options...
dadamssg Posted August 6, 2009 Author Share Posted August 6, 2009 f Quote Link to comment https://forums.phpfreaks.com/topic/168872-variable-can-only-have-certain-values/#findComment-891805 Share on other sites More sharing options...
wildteen88 Posted August 6, 2009 Share Posted August 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168872-variable-can-only-have-certain-values/#findComment-891815 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.