Home > php教程 > php手册 > 用ereg函数来判断用户权限

用ereg函数来判断用户权限

WBOY
Release: 2016-06-13 10:25:18
Original
967 people have browsed it

将用户权限存为型如以下格式
$perm=user,author,admin
若添加权限,则可用
$perm.=,XXXX;
添加权限字符串,其间用特殊字符分开,本例用的是“,”
程序中需要判断用户是否有$isperm权限时可以用以下代码:

$isperm=user;
if(ereg("$isperm", "$perm")){echo "
是普通用户";
}else{
echo "
不是普通用户"; }

$isperm=author;
if(ereg("$isperm", "$perm")){echo "
是版主";
}else{
echo "
不是版主"; }

$isperm=admin;
if(ereg("$isperm", "$perm")){echo "
是管理员";
}else{
echo "
不是管理员";}

必须指出的是,不同权限的名称不能互相包涵,如:
admin和bbsadmin
建议每个权限名称加上特有前缀或后缀,如:
bbsadmin、chatadmin、webadmin
就OK了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template