login.htm
代码如下 | 复制代码 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> |
login.php
代码如下 | 复制代码 |
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 '<script>alert("你还没登录!正在返回登录页面...");location.href="index.php";</script>'; exit(); } } |
退出登录
out.php
代码如下 | 复制代码 |
function loginOut() //登出函数 { if(isset($_GET["login"]) == 'out') { $_SESSION["user"] = ''; $_SESSION["pwd"] = ''; $_SESSION["id"] = ''; $_SESSION["name"] = ''; session_destroy(); echo '<script>alert("退出成功!");location.href="index.php"; </script>'; } } |
时间: 2024-10-14 10:03:58