时间:2021-07-01 10:21:17 帮助过:16人阅读
<?
function findsub($keys ,$userid='abc' ) //此函数重要就是为了调用用户的权限信息
{
include('user/'.$userid.'.php');
foreach($bb as $key=>$submenu)
{
foreach($submenu as $subkey=>$menuitem)
{
if( $subkey == $keys )
{
return 1;
}
}
}
}
//下面为生成用户的php权限文件
//写入
function cache_write($name, $var, $values) {
$cachefile = 'op/www.hzhuti.com/'.$name.'.php';
$cachetext = "<?phprn".'$'.$var.'='.arrayeval($values)."rn?>";
if(!swritefile($cachefile, $cachetext))
{
exit("File: $cachefile write error.");
}
}
//数组转换成字串
function arrayeval($array, $level = 0) {
$space = '';
for($i = 0; $i <= $level; $i++) {
$space .= "t";
}
$evaluate = "Arrayn$space(n";
$comma = $space;
foreach($array as $key => $val) {
$key = is_string($key) ? '''.addcslashes($key, ''\').''' : $key;
$val = !is_array($val) && (!preg_match("/^-?d+$/", $val) || strlen($val) > 12) ? '''.addcslashes($val, ''\').''' : $val;
if(is_array($val)) {
$evaluate .= "$comma$key => ".arrayeval($val, $level + 1);
} else {
$evaluate .= "$comma$key => $val";
}
$comma = ",n$space";
}
$evaluate .= "n$space)";
return $evaluate;
}
//写入文件
function swritefile($filename, $writetext, $openmod='w') {
if(@$fp = fopen($filename, $openmod)) {
flock($fp, 2);
fwrite($fp, $writetext);
fclose($fp);
return true;
} else {
exit("File: $filename write error.");
return false;
}
}
?>
adminconfig.php 后台权限配置文件,以一个数组形式保存
代码如下:
<?
$menus = array(
'news' => array(
'caption'=>'资讯管理',
'icon'=>'admin/icon_15.gif',
'sub' => array(
'newsaddtype' => array('caption' => '分类增加', 'url' => 'news/addtype.php'),
'newstypemange' => array('caption' => '分类管理', 'url' => 'news/typemange.php'),
'newsnewsend' => array('caption' => '发布资讯', 'url' => 'news/newsend.php'),
'newsnewmange' => array('caption' => '资讯管理', 'url' => 'news/newmange.php'),
'newscomments' => array('caption' => '评论管理', 'url' => 'news/comments.php'),
),
),
'ask' => array(
'caption'=>'问卷调查',
'icon'=>'admin/icon_15.gif',
'sub' => array(
'voteadmin_subject_add' => array('caption' => '添加投票主题', 'url' => 'vote/admin_subject_add.php'),
'voteadmin_subject' => array('caption' => '管理投票主题', 'url' => 'vote/admin_subject.php'),
'voteadmin_title_add' => array('caption' => '添加投票问题', 'url' => 'vote/admin_title_add.php'),
'voteadmin_title' => array('caption' => '管理投票问题', 'url' => 'vote/admin_title.php'),
'voteadmin_question_add' => array('caption' => '添加投票答案', 'url' => 'vote/admin_question_add.php'),
'voteadmin_question' => array('caption' => '管理投票答案', 'url' => 'vote/admin_question.php'),
'voteadmin_system' => array('caption' => '投票初始配置', 'url' => 'vote/admin_system.php')
),
),
'ads' => array(
'caption'=>'广告管理',
'icon'=>'admin/icon_15.gif',
'sub' => array(
'ada' => array('caption' => '增加广告', 'url' => 'ada.php'),
'adm' => array('caption' => '广告管理', 'url' => 'adm.php'),
'flashadd' => array('caption' => '焦点图广告增加', 'url' => 'flashadd.php'),
'flashad' => array('caption' => '焦点图广告管理', 'url' => 'flashad.php')
),
),
'mange' => array(
'caption'=>'系统管理员',
'icon'=>'admin/icon_15.gif',
'sub' => array(
'adminuser' => array('caption' => '管理员添加', 'url' => 'adminuser.php'),
'modpass' => array('caption' => '密码修改', 'url' => 'modpass.php')
),
),
);
?>
left.php文件很简单就是根据用户登录后ID读出权限
代码如下:
<?
$userid = $_SESSION['adminid'];
include("op/admincofig.php");
include("op/ www.hzhuti.com /".$userid.".php");
foreach($bb as $key=>$submenu)
{
echo "<tr><td bgcolor="#D879A7" style="line-height:22px;text-align:center;color:#ffffff;"> nr <font color="#EA6A8D" face="Webdings"></font><b>".$menus[$key]['caption']."</b><br /></td></tr> nr <tr ><td bgcolor="F5E8F1">";
foreach($submenu as $subkey=>$menuitem)
{
$tmparr = explode("|",$menuitem);
echo "<font color="#EA6A8D" face="Webdings">4</font><a href='".$tmparr[1]."' target="mainframe">".$tmparr[0]."</a><br> nr";
}
echo "</td></tr> nr ";
}
op.php这个文件就是要调用我们的adminconfig.php文件,然后利用fun.php文件中函数把提供过来的数据保存成数组如图
点击保存我们调用了opsava.php 文件,代码如下
代码如下:
<?
include("op/fun.php");
if( $_POST )
{
$sarray = $_POST ;
cache_write($userid,'bb',$sarray);//写入缓存
echo "<script>alert('编辑保存成功!');location='op.php?userid=".$userid."';</script>";
}
?>
保存成功后文件内容如
代码如下:
<?php
$bb=Array
(
'member' => Array
(
'user_search' => '会员升级管理|user_search.php'
),
'membercy' => Array
(
'cyuser_search' => '会员升级管理|cyuser_search.php',
'cyuser_search5' => '交友会员|cyuser_search.php?grade=5'
),
'userid' => 7,
'button' => '保存编辑'
)
?>
这样的话我们的left只要加载 7.php文件就只会显示这里在的文件,这样一个基本的后台权限就完成了。