php $_SESSION会员登录实例分享
作者:lijiao 时间:2024-06-05 09:47:58
php会员登录模块是网站开发中很简单的一个模块,本实例主要给php初学者一个简单的参考,其中的逻辑还是要读者自己领会,多编多思考。
login.php文件
<?php
ob_start();
session_start();
?>
<?
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
?>
<html lang="en">
<head>
<title>Tutorialspoint.com</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #ADABAB;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
color: #017572;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
border-color:#017572;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-color:#017572;
}
h2{
text-align: center;
color: #017572;
}
</style>
</head>
<body>
<h2>Enter Username and Password</h2>
<div class="container form-signin">
<?php
$msg = '';
if (isset($_POST['login']) && !empty($_POST['username']) && !empty($_POST['password'])) {
if ($_POST['username'] == 'tutorialspoint' && $_POST['password'] == '1234') {
$_SESSION['valid'] = true;
$_SESSION['timeout'] = time();
$_SESSION['username'] = 'tutorialspoint';
echo 'You have entered valid use name and password';
}
else
{
$msg = 'Wrong username or password';
}
}
?>
</div> <!-- /container -->
<div class="container">
<form class="form-signin" role="form" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<h4 class="form-signin-heading"><?php echo $msg; ?></h4>
<input type="text" class="form-control" name="username" placeholder="username = tutorialspoint" required autofocus></br>
<input type="password" class="form-control" name="password" placeholder="password = 1234" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" name="login">Login</button>
</form>
Click here to clean <a href="logout.php" tite="Logout">Session.
</div>
</body>
</html>
Logout.php文件
<?php
session_start();
unset($_SESSION["username"]);
unset($_SESSION["password"]);
echo 'You have cleaned session';
header('Refresh: 2; URL=login.php');
?>
标签:php,会员,登录
0
投稿
猜你喜欢
用Assets 面板为你的站点定做颜色
2007-02-03 11:39:00
在Python中利用pickle保存变量的实例
2021-05-04 04:25:50
开心网让人很不开心
2009-04-05 15:56:00
Python爬虫获取op.gg英雄联盟英雄对位胜率的源码
2024-01-02 13:03:52
浅析Python3爬虫登录模拟
2023-10-10 18:15:02
JS清除IE浏览器缓存的方法
2024-04-19 10:15:25
mysql 8.0.18 安装配置优化教程
2024-01-19 22:43:59
触手生春【4.13】CSS中的伪元素选择符
2008-11-11 13:10:00
详解CentOS升级Python2.6到Python2.7并安装pip
2023-06-13 18:59:45
Python检查图片是否损坏及图片类型是否正确过程详解
2021-04-07 22:26:12
平面设计中的文字设计
2009-01-15 12:09:00
对python中数组的del,remove,pop区别详解
2021-01-23 09:22:31
Python有序字典简单实现方法示例
2021-05-05 19:25:58
浅谈python标准库--functools.partial
2023-01-03 20:08:36
如何使用myisamchk和mysqlcheck工具快速修复损坏的MySQL数据库文件
2024-01-21 12:39:37
python super的使用方法及实例详解
2023-08-19 11:04:49
对python中的控制条件、循环和跳出详解
2022-03-08 00:41:44
Oracle常用dump命令,记录一下备查。
2009-03-04 10:27:00
利用Python将时间或时间间隔转为ISO 8601格式方法示例
2022-12-06 22:18:25
uber go zap 日志框架支持异步日志输出
2024-04-25 15:27:49