phpmady Posted April 25, 2010 Share Posted April 25, 2010 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 Link to comment https://forums.phpfreaks.com/topic/199681-how-to-check-against-the-session-variable-with-array/ Share on other sites More sharing options...
cags Posted April 25, 2010 Share Posted April 25, 2010 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. Link to comment https://forums.phpfreaks.com/topic/199681-how-to-check-against-the-session-variable-with-array/#findComment-1048031 Share on other sites More sharing options...
phpmady Posted April 25, 2010 Author Share Posted April 25, 2010 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... Link to comment https://forums.phpfreaks.com/topic/199681-how-to-check-against-the-session-variable-with-array/#findComment-1048056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.