Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

quick php variable question

Featured Replies

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

session_start();

$_SESSION['usergroup'][1] = 100; 
$_SESSION['usergroup'][2] = 40; 

echo $_SESSION['usergroup'][1].'<br />';
echo $_SESSION['usergroup'][2];

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.

  • 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 ;)

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.