PHP-登录示例
PHP-登录示例 使用会话登录PHP Php登录脚本用于为我们的网页提供身份验证。提交用户登录按钮后,脚本将执…
PHP-登录示例
使用会话登录PHP
Php登录脚本用于为我们的网页提供身份验证。提交用户登录按钮后,脚本将执行。
登录页面
登录页面应如下所示,并基于会话进行工作。如果用户关闭会话,它将清除会话数据。
现场演示
<?php ob_start();
session_start();
??>
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
?>
<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>
<h2>Enter Username and Password</h2>
<div>
<?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>
<form role="form" action="<?php%20echo%20htmlspecialchars(%24_SERVER%5B'PHP_SELF'%5D);%20%0A%20%20%20%20%20%20%20%20%20%20%20%20?>" method="post">
<h4><?php echo $msg; ??></h4>
<input type="text" name="username" placeholder="username = tutorialspoint" required="" autofocus="">
<input type="password" name="password" placeholder="password = 1234" required="">
<button type="submit" name="login">Login</button>
</form>
Click here to clean <a href="logout.php" tite="Logout">Session.
</a></div>
注销.php
它将删除会话数据。
<?php session_start();
unset($_SESSION["username"]);
unset($_SESSION["password"]);
echo 'You have cleaned session';
header('Refresh: 2; URL = login.php');
??>
它将产生以下结果-

类别:PHP 技巧、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!