Jump to content

How to Check against the session variable with array


phpmady

Recommended Posts

Hi,

 

I am trying to do this .... can u pls give me a idea in php..

 

 

$_SESSION[permissions] == "news,users,settings";

 

 

 

//checking any one of the string remains

if(news ==  $_SESSION[permissions])

{

 

echo "redirect to the news page";

}

else

{

 

echo "Sorrry u dont have permission tho the page";

 

}

 

cheers

Not entirely sure I'm understanding you correctly but... First you will need the data in the session variable to be an array, not a comma separated string.

 

$_SESSION['permissions'] = array('news', 'users', 'settings');

Then you can use.

 

if( in_array( 'news', $_SESSION['permissions'] ) ) {
   // redirect
} else {
   // not allowed
}

There are of course other methods.

Not entirely sure I'm understanding you correctly but... First you will need the data in the session variable to be an array, not a comma separated string.

 

$_SESSION['permissions'] = array('news', 'users', 'settings');

Then you can use.

 

if( in_array( 'news', $_SESSION['permissions'] ) ) {
   // redirect
} else {
   // not allowed
}

There are of course other methods.

 

thank you very much

cheers...

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.