June 1, 200917 yr Hi, im having trouble setting a php variable for my gaming ladder script. Im setting admin group permissions to allow a group access to a specific variable (i think thats what you call it) .. simply put i want a newly created admin group access to changing ladder rules. The code im editing is if($_SESSION['rights'] == 100){ The 100 represents a user group and im trying to add the user group 40 in there aswell. Ive tried if($_SESSION['rights'] == 40,100){ but that didnt seem to do it. im sure this is pretty easy stuff if you understand php just i havent been able to bring myself to learn it yet i know i should though ... any ideas how i can do this ? would be appreciated. Thanks, Mark
June 2, 200917 yr session_start(); $_SESSION['usergroup'][1] = 100; $_SESSION['usergroup'][2] = 40; echo $_SESSION['usergroup'][1].'<br />'; echo $_SESSION['usergroup'][2];
June 2, 200917 yr I'm not sure what you're asking for, but it looks like you need to send an array to the session $_SESSION['rights'][]='40'; $_SESSION['rights'][]='100'; The second set of parentheses assigns the value a new place in the $_SESSION['rights'] array. Then you can iterate over these values using a loop in your recieving script: $rights = $_SESSION['rights']; //test to see if it's an array if(is_array($rights)){ //foreach($rights as $r){ switch($rights){ case '100': //do this case '40': //do that }//end switch }//end foreach }// end is_array if else... ...perform same test for single variable i.e: if $rights is not an array. since you are likely to test against the same criteria, you might want to house the switch in a function so it can be called against arrays and variables alike.
June 2, 200917 yr Author Thanks guys in the end ive used if($_SESSION['rights'] == 100); if($_SESSION['rights'] == 40){ i figured that out after your suggestions so thanks really helped me out there
June 2, 200917 yr The standard way of doing that would be using the || (or) logical operator. So you would have: if($_SESSION['rights'] == 100 || $_SESSION['rights'] == 40) { //strut your stuff here } Literally, the || means "or". You can also use && for "and", > for "more than" and so on. A full list of PHP's logical operators is available here. Dan
Create an account or sign in to comment