php登录与退出登录实例代码
login.htm
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9225')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9225><!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>
<form id="form1" name="form1" method="post" action="">
<p>
<label for="user"></label>
<input type="text" name="user" id="user" />
</p>
<p>
<label for="pwd"></label>
<input type="text" name="pwd" id="pwd" />
</p>
<p>
<input type="submit" name="button" id="button" value="提交" />
</p>
</form>
</body>
</html>
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
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5080')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5080>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>';
}
}
您可能感兴趣的文章:
php实现记住密码自动登录的功能
php登录后如何点击退出登录?
php登录页面(复杂型)代码
PHP CURL获取cookies模拟登录的方法介绍
PHP 登录完成跳转上一访问页面
php登录与退出登录实例代码
帝国cms系统安全配置最优化
UCenter单点登录/同步登录/同步登出实例
JS 退出系统并跳转到登录界面的代码一例
asp.net单点登录实现