function showPage() //判断是否登录 未登录直接跳转至登录页面 { if(!isset($_SESSION["user"]) && !isset($_SESSION["pwd"])) { if(isset($_COOKIE["user"]) && isset($_COOKIE["pwd"])) { $sql = "select * from pm_user where u_user='$_COOKIE[user]'"; $query = mysql_query($sql); $isUser = is_array($row = mysql_fetch_array($query)); //判断用户名 $isPwd = $isUser ? $row["u_pwd"] == $_COOKIE["pwd"] : false; //判断密码 if($isPwd) { $_SESSION["user"] = $_COOKIE["user"]; $_SESSION["pwd"] = $_COOKIE["pwd"]; $_SESSION["id"] = $_COOKIE["id"]; $_SESSION["name"] = $_COOKIE["name"]; } } } if(!isset($_SESSION["user"]) && !isset($_SESSION["pwd"])) { echo ''; exit(); } } 退出登录 out.php
代码如下 | 复制代码 | function loginOut() //登出函数 { if(isset($_GET["login"]) == 'out') { $_SESSION["user"] = ''; $_SESSION["pwd"] = ''; $_SESSION["id"] = ''; $_SESSION["name"] = ''; session_destroy(); echo ''; } } |
|