1. 程式人生 > >.php會員登入許可權和超時退出

.php會員登入許可權和超時退出

config.php

<?php
session_start();
$conn = @ mysql_connect("localhost", "root", "") or die("資料庫連結錯誤");
mysql_select_db('menber',$conn);
mysql_query("set names 'GBK'");
define(ALL_PS,"php100");


 function user_shell($uid,$shell,$m_id){
  $sql="select * from user_list where uid= '$uid'";
  $query=mysql_query($sql);
  $us=is_array($row=mysql_fetch_array($query));
  $shell=$us ? $shell==md5($row[username].$row[password].ALL_PS):FALSE;
  if($shell){
    if($row[m_id]<=$m_id) {
    return $row;
    }else{
   echo "你的許可權不足";
    exit();  
      }

  }else{
   echo "你無許可權訪問該頁";
   exit();  
  }
 }
 
 
 
 function user_mktime($onlinetime) {
 
  $new_time=mktime();

  if($new_time-$onlinetime>'10'){
   echo "登陸超時";
   exit();
   //session_destroy();
   }else{
   $_SESSION[times]=mktime();  
   }   
 }
?>

user.php

<?php
 include("config.php");
 
 if($_POST[Submit]){
  $username=str_replace(" ","",$_POST[username]);
  $sql="select * from user_list where username= '$username'";
  $query=mysql_query($sql);
  $us=is_array($row=mysql_fetch_array($query));
  
  
  $ps= $us ? md5($_POST[password].ALL_PS) == $row[password] : FALSE;
  if($ps){
   $_SESSION[uid]=$row[uid];
   $_SESSION[user_shell]=md5($row[username].$row[password].ALL_PS);
   $_SESSION[times]=mktime();
   echo "登陸成功";
   }else{
   echo "登陸失敗";
   session_destroy();  
  
  }
   
 }
?>

<form method="post" action="">
  <p>使用者名稱:
    <label>
    <input name="username" type="text" id="username" />
    </label>
  </p>
  <p>密碼:
    <label>
    <input name="password" type="password" id="password" />
    </label>
  </p>
  <p>
    <label>
    <input type="Submit" name="Submit" value="提交" />
    </label>
  </p>
  <p>&nbsp;</p>
</form>

user_sys.php

<?php
 include("config.php");

    $arr=user_shell($_SESSION[uid],$_SESSION[user_shell],1);

user_mktime($_SESSION[times])
 
?>
許可權內容