php - Check if usergroup exists -
i have 2 variables both hold comma separated lists. 1 permissions variable , other usergroup list of person wanting access page.
1 = user
2 = editor
3 = moderator
4 = admin
<?php $query = mysql_query("select * users id='{$user['id']}'"); $user = mysql_fetch_assoc($query); $query2 = mysql_query("select * menu active='1'"); $page = mysql_fetch_assoc($query2); echo $user['usergroup']; // 1 echo $page['usergroup']; // 2,3,4 ?>
i need find way compare both variables check if have right usergroup access page
if $user['usergroup'] contains number $page['usergroup'] x otherwise y
thanks :)
$user = "1,3,5"; $page = "1,2,5"; //explode , trim case have spaces '1, 2,3 ,4' $u = array_map('trim', explode(",", $user)); $p = array_map('trim', explode(",", $page)); $intersect = array_intersect( $u, $p ); if ( count($intersect) ) { //ok print_r( $intersect ); } else { //error }
allowed permissions:
array ( [0] => 1 [2] => 5 )
Comments
Post a Comment