PHP登录Cookie保持登录
直接上源码
login.html
<div>
<h1>PHP简易登录</h1><br>
<form action="login.php" method="post">
<label for="fname">用户名</label>
<input type="text" name="u_name" placeholder="用户名" />
<label for="lname">密码</label>
<input type="password" name="u_pass" placeholder="密码" />
<label for="country">保持连接</label>
<select name="cookie" id="cookie">
<option value="0" selected>30分钟</option>
<option value="1">3天</option>
<option value="2">30天</option>
</select>
<button type="submit" class="btn" name="login">登录</button>
<ul>
<li><a href="javascript:void()">忘记密码</a></li>
<li><a href="javascript:void()">系统管理</a></li>
</ul>
</form>
</div>
login.php
<?php
header ("Content-Type:text/html;charset=UTF-8");
$username = $_POST['u_name'];
$passcode = $_POST['u_pass'];
if ($username !="" && $passcode !=""){
switch ($cookie)
{
case 0:
setcookie ("username",$username,time()+60*30);
break;
case 1:
setcookie ("username",$username,time()+60*60*24*3);
break;
case 2:
setcookie ("username",$username,time()+60*60*24*30);
break;
}
header ("location:system.php");
}else{
echo "用户名或密码错误<br>";
header("refresh:3;url=login.html");
print('正在加载,请稍等...<br>3秒后自动跳转。');
}
?>
全套源码带注销登录源码请转至:https://download.csdn.net/download/munanshang/20036497?spm=1001.2014.3001.5503
|