php $_SESSION會(huì)員登錄實(shí)例分享
php會(huì)員登錄模塊是網(wǎng)站開發(fā)中很簡(jiǎn)單的一個(gè)模塊,本實(shí)例主要給php初學(xué)者一個(gè)簡(jiǎn)單的參考,其中的邏輯還是要讀者自己領(lǐng)會(huì),多編多思考。
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'); ?>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
- PHP實(shí)現(xiàn)會(huì)員賬號(hào)單唯一登錄的方法分析
- PHP+MYSQL會(huì)員系統(tǒng)的登陸即權(quán)限判斷實(shí)現(xiàn)代碼
- 實(shí)用PHP會(huì)員權(quán)限控制實(shí)現(xiàn)原理分析
- php+MySQL實(shí)現(xiàn)登錄時(shí)驗(yàn)證登錄名和密碼是否正確
- php session應(yīng)用實(shí)例 登錄驗(yàn)證
- php cookie 登錄驗(yàn)證示例代碼
- PHP登錄驗(yàn)證碼的實(shí)現(xiàn)與使用方法
- php自動(dòng)注冊(cè)登錄驗(yàn)證機(jī)制實(shí)現(xiàn)代碼
- php面向?qū)ο蟮挠脩舻卿浬矸蒡?yàn)證
- php 實(shí)現(xiàn)賬號(hào)不能同時(shí)登陸的方法分析【當(dāng)其它地方登陸時(shí),當(dāng)前賬號(hào)失效】
相關(guān)文章
PHP實(shí)現(xiàn)Redis分布式鎖的示例代碼
并發(fā)寫入問題可能導(dǎo)致數(shù)據(jù)不一致或重復(fù)寫入,為了解決這個(gè)問題,我們可以使用Redis實(shí)現(xiàn)分布式鎖,本文主要為大家介紹了PHP實(shí)現(xiàn)Redis分布式鎖的相關(guān)知識(shí),希望對(duì)大家有所幫助2023-12-12基于PHP實(shí)現(xiàn)短信驗(yàn)證碼發(fā)送次數(shù)限制
這篇文章主要介紹了基于PHP實(shí)現(xiàn)短信驗(yàn)證碼發(fā)送次數(shù)限制,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07php生成SessionID和圖片校驗(yàn)碼的思路和實(shí)現(xiàn)代碼
做一個(gè)后臺(tái)登陸需要用到校驗(yàn)碼,前臺(tái)的用戶跟蹤需要用到SessionID,當(dāng)然,默認(rèn)的PHP開啟了Session以后就有了一個(gè)SessionID,但是我需要自己的,并且能夠存儲(chǔ)進(jìn)數(shù)據(jù)庫,那么我就嘗試了一下,構(gòu)造了以下的函數(shù)。2009-03-03淺談php字符串反轉(zhuǎn) 面試中經(jīng)常遇到
下面小編就為大家分享一篇淺談php字符串反轉(zhuǎn) 面試中經(jīng)常遇到的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01PHP 遠(yuǎn)程文件管理,可以給表格排序,遍歷目錄,時(shí)間排序
PHP 遠(yuǎn)程文件管理,可以給表格排序,遍歷目錄,時(shí)間排序 點(diǎn)擊表格第一行,頭部就可以排序了,這個(gè)列子是當(dāng)前目錄的2009-08-08php將字符串轉(zhuǎn)化成date存入數(shù)據(jù)庫的兩種方式
這篇文章主要介紹了php將字符串轉(zhuǎn)化成date存入數(shù)據(jù)庫的兩種方式,需要的朋友可以參考下2014-04-04php實(shí)現(xiàn)網(wǎng)頁上一頁下一頁翻頁過程詳解
這篇文章主要介紹了php實(shí)現(xiàn)網(wǎng)頁上一頁下一頁翻頁過程詳解,大致功能就是頁面只顯示幾條信息,按上一頁、下一頁切換內(nèi)容,當(dāng)顯示第一頁時(shí)上一頁和首頁選項(xiàng)不可選,當(dāng)頁面加載到最后一頁時(shí)下一頁和尾頁選項(xiàng)不可選,需要的朋友可以參考下2019-06-06