Home >Backend Development >PHP Tutorial >Use the ereg function to determine user permissions_PHP tutorial
Save user permissions in the following format:
$perm=user,author,admin
If you want to add permissions, you can use
$perm.=,XXXX;
to add permission strings, with special characters in between Characters are separated. This example uses ","
When you need to determine whether the user has $isperm permissions in the program, you can use the following code:
$isperm=user;
if(ereg("$ isperm", "$perm")){echo "
is an ordinary user";
}else{
echo "
is not an ordinary user"; }
$isperm=author ;
if(ereg("$isperm", "$perm")){echo "
is a moderator";
}else{
echo "
is not a moderator"; }
$isperm=admin;
if(ereg("$isperm", "$perm")){echo "
is the administrator";
}else{
echo "
Not an administrator";}
It must be pointed out that the names of different permissions cannot be inclusive of each other, such as:
admin and bbsadmin
It is recommended that each permission name be added with a unique prefix or Suffixes, such as:
bbsadmin, chatadmin, webadmin
are OK.