批改狀態(tài):未批改
老師批語(yǔ):
1.cookie方式
<?php // 防止重復(fù)登錄 if (isset($_COOKIE['username']) && $_COOKIE['username'] === 'admin') { echo '<script>alert("您已經(jīng)登錄,請(qǐng)不要重復(fù)登錄");location.assign("admin.php");</script>'; die; } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用戶登錄</title> <link rel="stylesheet" href="static/css/bootstrap.css"> </head> <body> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <h3 class="text-center"><strong>用戶登錄</strong></h3> <form class="form-horizontal" action="check.php" method="post" onsubmit="return isEmpty()"> <div class="form-group"> <label for="email" class="col-sm-2 control-label">郵箱</label> <div class="col-sm-10"> <input type="email" name="email" class="form-control" id="email" placeholder="Email"> </div> </div> <div class="form-group"> <label for="password" class="col-sm-2 control-label">密碼</label> <div class="col-sm-10"> <input type="password" name="password" class="form-control" id="password" placeholder="Password"> </div> </div> <!-- <div class="form-group">--> <!-- <div class="col-sm-offset-2 col-sm-10">--> <!-- <div class="checkbox">--> <!-- <label>--> <!-- <input type="checkbox"> Remember me--> <!-- </label>--> <!-- </div>--> <!-- </div>--> <!-- </div>--> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">提交</button> </div> </div> </form> </div> </div> <script> //非空驗(yàn)證 function isEmpty() { var email = document.getElementById('email').value; var password = document.getElementById('password').value; console.log(email); if (email.length === 0 || password.length === 0 ) { alert('郵箱或密碼不能為空!'); return false; } } </script> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
2.session方式
<?php session_start(); // 防止重復(fù)登錄 if (isset($_SESSION['username']) && $_SESSION['username'] === 'admin') { echo '<script>alert("您已經(jīng)登錄,請(qǐng)不要重復(fù)登錄");location.assign("admin.php");</script>'; die; } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用戶登錄</title> <link rel="stylesheet" href="static/css/bootstrap.css"> </head> <body> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <h3 class="text-center"><strong>用戶登錄</strong></h3> <form class="form-horizontal" action="check.php" method="post" onsubmit="return isEmpty()"> <div class="form-group"> <label for="email" class="col-sm-2 control-label">郵箱</label> <div class="col-sm-10"> <input type="email" name="email" class="form-control" id="email" placeholder="Email"> </div> </div> <div class="form-group"> <label for="password" class="col-sm-2 control-label">密碼</label> <div class="col-sm-10"> <input type="password" name="password" class="form-control" id="password" placeholder="Password"> </div> </div> <!-- <div class="form-group">--> <!-- <div class="col-sm-offset-2 col-sm-10">--> <!-- <div class="checkbox">--> <!-- <label>--> <!-- <input type="checkbox"> Remember me--> <!-- </label>--> <!-- </div>--> <!-- </div>--> <!-- </div>--> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">提交</button> </div> </div> </form> </div> </div> <script> //非空驗(yàn)證 function isEmpty() { var email = document.getElementById('email').value; var password = document.getElementById('password').value; // console.log(email); if (email.length === 0 || password.length === 0 ) { alert('郵箱或密碼不能為空!'); return false; } } </script> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)