虽然是说简单的数据库连接代码,但最终是来判断用户权限的,设置权重代码如下:
- <?php
- 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'] <= $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();
- }
-
- }
- ?>
|