虽然是说简单的数据库连接代码,但最终是来判断用户权限的,有需要的朋友可以参考一下。
<script>ec(2);</script>
代码如下 |
复制代码 |
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();
}
}
?>
|