本篇内容介绍了“如何实现php $_SESSION会员登录”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
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; } h3{ text-align: center; color: #017572; } </style> </head> <body> <h3>Enter Username and Password</h3> <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"> <h5 class="form-signin-heading"><?php echo $msg; ?></h5> <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 $_SESSION会员登录”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。