Home > Backend Development > PHP Tutorial > php $_SESSION member login example sharing, _session member login_PHP tutorial

php $_SESSION member login example sharing, _session member login_PHP tutorial

WBOY
Release: 2016-07-12 08:55:12
Original
884 people have browsed it

php $_SESSION member login example sharing, _session member login

php member login module is a very simple module in website development. This example mainly gives PHP beginners a simple For reference, readers still need to understand the logic and compile more.
login.php file

<&#63;php
  ob_start();
  session_start();
&#63;>
<&#63;
  // error_reporting(E_ALL);
  // ini_set("display_errors", 1);
&#63;>
<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">     
     <&#63;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';
        }
      }
     &#63;>
   </div> <!-- /container -->   
   <div class="container">   
     <form class="form-signin" role="form" action="<&#63;php echo htmlspecialchars($_SERVER['PHP_SELF']); &#63;>" method="post">
      <h4 class="form-signin-heading"><&#63;php echo $msg; &#63;></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>
Copy after login

Logout.php file

<&#63;php
  session_start();
  unset($_SESSION["username"]);
  unset($_SESSION["password"]); 
  echo 'You have cleaned session';
  header('Refresh: 2; URL=login.php');
&#63;>
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone’s study.

Articles you may be interested in:

  • php code to import member data into ucenter
  • Practical PHP member permission control implementation principle analysis
  • PHP MYSQL The login of the membership system is the authorization judgment implementation code
  • php development document membership fee 1 issue
  • PHP MYSQL membership system development example tutorial
  • php uses $_POST or $_SESSION[ ] Pass parameters to js function
  • PHP implementation to generate unique membership card number

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117078.htmlTechArticlephp $_SESSION member login example sharing, _session member login php member login module is a very simple module in website development , this example mainly provides a simple reference for PHP beginners, its...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template