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');
?>
以上就是本文的全部内容,希望对大家的学习有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!