服务器之家

服务器之家 > 正文

php $_SESSION会员登录实例分享

时间:2021-01-06 15:25     来源/作者:PHP教程网

php会员登录模块是网站开发中很简单的一个模块,本实例主要给php初学者一个简单的参考,其中的逻辑还是要读者自己领会,多编多思考。
login.php文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?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文件

?
1
2
3
4
5
6
7
<?php
  session_start();
  unset($_SESSION["username"]);
  unset($_SESSION["password"]);
  echo 'You have cleaned session';
  header('Refresh: 2; URL=login.php');
?>

php $_SESSION会员登录实例分享

以上就是本文的全部内容,希望对大家的学习有所帮助。

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部