亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 48
粉絲 0
評論 3
訪問量 57063
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
用戶登錄及注銷
江流
原創(chuàng)
890人瀏覽過

顯示用戶登錄代碼 login.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>用戶登錄</title>
  8. <style>
  9. .login {
  10. width: 480px;
  11. margin: 0 auto;
  12. padding: 20px;
  13. background-color: lightblue;
  14. }
  15. form {
  16. display: grid;
  17. gap: 0.5rem;
  18. }
  19. form * {
  20. margin: 5px 20px;
  21. }
  22. h2 {
  23. text-align: center;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div class="login">
  29. <h2>用戶登錄</h2>
  30. <form action="">
  31. <fieldset>
  32. <div>
  33. <label for="account">賬 戶:</label>
  34. <input
  35. type="text"
  36. id="account"
  37. name="account"
  38. required
  39. placeholder="請輸入用戶名"
  40. />
  41. </div>
  42. <div>
  43. <label for="password">密 碼:</label>
  44. <input
  45. type="password"
  46. id="password"
  47. name="password"
  48. required
  49. placeholder="請輸入密碼"
  50. />
  51. </div>
  52. </fieldset>
  53. <button type="button" onclick="check(this.form)">登錄</button>
  54. </form>
  55. </div>
  56. <script>
  57. function check(thisForm) {
  58. const account = thisForm.account.value.trim();
  59. const password = thisForm.password.value.trim();
  60. //加密成JSON數(shù)據(jù)
  61. const user = JSON.stringify({ account: account, password: password });
  62. fetch("check.php", { method: "post", body: user })
  63. .then((response) => response.json())
  64. .then((json) => {
  65. if (json.status != 0) {
  66. alert(json.msg);
  67. return false;
  68. }
  69. alert(json.msg);
  70. setTimeout(() => {
  71. window.location.href = "showuser.php";
  72. }, 1000);
  73. });
  74. }
  75. </script>
  76. </body>
  77. </html>

  • check.php文件
  1. <?php
  2. require_once "auto.php";
  3. session_start();
  4. header("Content-Type:application/json");
  5. $data=trim(file_get_contents('php://input'));
  6. // json 轉(zhuǎn)為數(shù)組
  7. $user=json_decode($data,true);
  8. //
  9. $res=UserContr::login($user['account'],$user['password']);
  10. if($res['stutas']==0){
  11. setcookie('id',1);
  12. $_SESSION['account']=$user['account'];
  13. }
  14. echo json_encode($res);
  • UserContr.php文件UserContr類中的用戶登錄代碼
  1. //用戶登錄
  2. public static function login($account,$password){
  3. $pdo =CreatePDO::Create();
  4. $sql="SELECT * FROM `php_user` WHERE account='".$account."'";
  5. $pre=$pdo->prepare($sql);
  6. $exec=$pre->execute();
  7. $arr=$pre->fetch();
  8. if(empty($arr)){
  9. $res=['status'=>1,'msg'=>'用戶不存在'];
  10. }elseif($arr['password']!=md5($password)){
  11. $res=['status'=>2,'msg'=>'密碼不正確'];
  12. }else{
  13. $res=['status'=>0,'msg'=>'登錄成功'];
  14. }
  15. return $res;
  16. }
  • header.php 文件
  1. <?php
  2. session_start();
  3. if(empty($_COOKIE['id'])){
  4. echo "<script>window.location.href='login.html'</script>";
  5. exit;
  6. }
  7. $account=$_SESSION['account'];
  8. ?>
  9. <div class="header">
  10. <div><span><?=$account?></span> <a href="destroy.php">注銷</a>
  11. </div>
  12. </div>
  13. <style>
  14. *{
  15. margin: 0;
  16. padding: 0;
  17. }
  18. .header{
  19. height: 30px;
  20. background-color: purple;
  21. }
  22. .header div{
  23. width: 15em;
  24. margin:5px 0px ;
  25. position: fixed;
  26. right: 2px;
  27. color: lightsalmon;
  28. }
  29. a{
  30. text-decoration: none;
  31. }
  32. .header a{
  33. margin:auto 1rem;
  34. color: #eee;
  35. }
  36. </style>
  • 在showuser.php文件中引入header.php文件。
  1. <?php require_once "header.php" ?>

  • 注銷文件 destroy.php
  1. <?php
  2. setcookie('id',1,time());
  3. $_SESSION['account']=null;
  4. echo '<script>alert("退出登錄");location.href="login.html"</script>';
批改老師:PHPzPHPz

批改狀態(tài):合格

老師批語:
本博文版權(quán)歸博主所有,轉(zhuǎn)載請注明地址!如有侵權(quán)、違法,請聯(lián)系admin@php.cn舉報處理!
全部評論 文明上網(wǎng)理性發(fā)言,請遵守新聞評論服務(wù)協(xié)議
0條評論
作者最新博文
關(guān)于我們 免責(zé)申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!
關(guān)注服務(wù)號 技術(shù)交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費學(xué)