复制代码 代码如下:
error_reporting(0);
session_start();
//数据库连接
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('chenkun', $conn);
mysql_query('SET NAMES UTF-8');
//定义常量
define('ALL_PS', 'PHP');
function user_shell($uid, $shell, $m_id) {
$sql = "select * from admin where uid='$uid'";
$query = mysql_query($sql);
$row = mysql_fetch_array($query);
$shell = is_array($row) ? $shell == md5($row['username'] . $row['password'] . ALL_PS) : FALSE;
if ($shell) {
if ($row['m_id'] return $row;
}
echo "你的权限不足";
exit ();
} else {
echo "你无权限访问该页";
exit ();
}
}
function user_mktime($onlinetime) {
$new_time = mktime();
if (($new_time - $onlinetime) > '900') {
session_destroy();
echo "登陆超时";
exit ();
} else {
$_SESSION['times'] = mktime();
}
}
?>
复制代码 代码如下:
//启动session
session_start();
//数据库连接
$conn=mysql_connect('localhost','root','******');
mysql_select_db('test',$conn);
//定义常量
define("ALL_PS","php100");
//判断权限函数
function user_shell($uid,$shell){
$sql="SELECT * FROM `user_list` WHERE `uid` = '$uid'";
$query=mysql_query($sql);
$exist=is_array($row=mysql_fetch_array($query));
$exist2=$exist?$shell==md5($row['username'].$row['password'].ALL_PS):FALSE;
if($exist2){
return $row;
}else{
echo "你无权限访问该页";
exit();
}
}
?>
复制代码 代码如下:
include("config.php");
if($_POST['submit']){
$username=str_replace(" ","",$_POST['username']); //去除空格
$sql="SELECT * FROM `user_list` WHERE `username` = '$username'";
$query=mysql_query($sql);
$exist=is_array($row=mysql_fetch_array($query)); //判断是否存在这样一个用户
$exist2=$exist?md5($_POST['password'].ALL_PS)==$row['password']:FALSE;//判断密码
if($exist2){
$_SESSION['uid']=$row['uid']; // session赋值
$_SESSION['user_shell']=md5($row['username'].$row['password'].ALL_PS);
echo "登陆成功";
}else{
echo "不正确的用户名";
SESSION_DESTROY();
}
}
?>
复制代码 代码如下:
include("config.php");
$arr=user_shell($_SESSION['uid'],$_SESSION['user_shell']);//以上两句即可对权限进行判断
echo $arr['username'];
?>
权限内容