Jump to content

Recommended Posts

Looking for an explanation

 

I have three different user levels and I want to grant page access depending on the level.

Say the levels are:

Level A

Level B

Level C

 

On this page I only want Levels A and B to access it

 

I have it working by checking the Session value like this

if ($_SESSION['user_level'] != 'A'){

if ($_SESSION['user_level'] != 'B'){

//redirect to the restricted page notice
}
}

 

But it wouldnt work by doing any variation on one line in the if statement??

i.e.

if (!isset($_SESSION['user_level']) || ($_SESSION['user_level'] != 'A')|| ($_SESSION['user_level'] != 'B')) {
//redirect to the restricted page notice
}

it simply redirects everyone.

 

Is there a way to get it on lne line vs. nesting the if statements - just out of curiosity.. THanks

Link to comment
https://forums.phpfreaks.com/topic/270025-comparing-sessions-using/
Share on other sites

Hi there,

you can simply change your statement to the below:

if (!isset($_SESSION['user_level']) || ( ($_SESSION['user_level'] != 'A') AND ($_SESSION['user_level'] != 'B')) ) {
//redirect to the restricted page notice
}

 

That should work

Edited by OOP
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.