Home > Backend Development > PHP7 > body text

Record PHP7 message board development background management-login/logout

coldplay.xixi
Release: 2023-02-17 18:16:01
forward
1935 people have browsed it

php7 tutorialThe column introduces how to develop a message board

Record PHP7 message board development background management-login/logout

Recommended (free): php7 tutorial

Foreword: It has not been updated for a while, so I will post the rest The tutorial is finished. It’s still the same as before, start typing code.

Main knowledge points in this step:

1. Super global variable $_SESSIONThe application saves the login status. Note that session_start() must be used before use.
2. Give ordinary Add salt value to the password to strengthen the password
3. Log out and log in, check the logout.php code

1, template

html code

nbsp;html>


<meta>
<title>留言表单后台登录_科科分享</title>
<link>


<p>
  </p><p>
    </p><p>
      </p><p>
        </p><h3>留言表单后台登录</h3>
        <h5><span>FEEDBACK</span></h5>
      
      <p>
        </p>
Copy after login
          

                                    

                   
              

css code

* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
*:before, *:after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

h1, h2, h3, h3, h4, h5, h6 {
    font-weight: normal;
}

body {
    font-family:"微软雅黑", "Microsoft Yahei";
}
.wp {
    width: 100%;
    max-width: 1170px;
    margin: 0 auto;
}
a {
    color: #333;
}
a:hover {
    color: #e4392a;
}

#hd {
    /*height: 101px;*/
    height: 90px;
    background: #fff;
    box-shadow: 0px 2px 2px rgba(0, 0, 0, .3);
    position: fixed;
    width: 100%;
    left: 0;
    top: 0;
    z-index:9999;
    -o-transition:.3s;
    -ms-transition:.3s;
    -moz-transition:.3s;
    -webkit-transition:.3s;
    transition:.3s;
}

.tit-i {
    text-align: center;
    padding: 50px 0;
    line-height: 36px;
    overflow: hidden;
}
.tit-i h3 {
    font-size: 30px;
    color: #002;
    margin-bottom: 10px;
}
.tit-i h5 {
    font-size: 20px;
    color: #cacace;
    text-transform: uppercase;
    font-family: Arial;
}
.tit-i h5 span {
    color: #e4392a;
}
.tit-i em {
    width: 45px;
    border-bottom: 1px solid #7f7f90;
    display: inline-block;
}

.login-l {
    width: 38%;
    float: left;
}
.login-r {
    width: 50%;
    margin: 0 auto;
}

.login-form .inp {
    width: 49%;
    border: 1px solid #6d6d88;
    height: 33px;
    padding: 0 10px;
    margin-bottom: 15px;
}
.login-form textarea {
    width: 100%;
    border: 1px solid #6d6d88;
    height: 98px;
    margin-bottom: 24px;
}
.login-form .sub {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: center;
    color: #fff;
    background-color: #63637f;
    border: 0;
    cursor: pointer;
    font-family:"微软雅黑", "Microsoft Yahei";
    font-size: 16px;
}

.list ul{
    padding: 20px 0;
    width: 50%;
    margin: 0 auto;
}
.list .tit-i{
    padding: 50px 0 10px 0;
}
.list ul li{line-height: 1.8em;color: #666;}
Copy after login

2. Data operation

--
-- 表的结构 `admin`
--

CREATE TABLE `admin` (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `login_name` varchar(128) NOT NULL COMMENT '登录账号',
  `password` varchar(64) NOT NULL COMMENT '登录密码',
  `salt` char(4) NOT NULL COMMENT '盐值,加强密码强度',
  `addtime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '记录时间',
  PRIMARY KEY (`id`),
  KEY `login_name` (`login_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='管理员数据表';
Copy after login

login.php

<?php include &#39;config.php&#39;;

$login_name = !empty($_POST[&#39;login_name&#39;])? addslashes(strip_tags($_POST[&#39;login_name&#39;])):&#39;&#39;;
$password = !empty($_POST[&#39;password&#39;])?addslashes(strip_tags($_POST[&#39;password&#39;])):&#39;&#39;;

// 简单验证一下提交的数据
if (empty($login_name) || empty($password)) {
    exit(&#39;请输入登录信息!&#39;);
}
$sql = "SELECT * FROM admin WHERE `login_name` = &#39;{$login_name}&#39; LIMIT 1";
$result = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_array($result);
if (empty($row)) {
    exit(&#39;账号密码错误!&#39;);
}
$res_password = $row[&#39;password&#39;];
$password = md5(md5($password) . $row[&#39;salt&#39;]);
// 密码不匹配
if ($res_password != $password) {
    exit(&#39;账号密码错误!&#39;); // 为了程序的安全,这里不必具体提示密码错误,告知用户账号或密码错误即可。
}
// 登录成功,保存登录信息,一般都用session进行处理
session_start();
$_SESSION[&#39;login_admin_id&#39;] = $row[&#39;id&#39;];
$_SESSION[&#39;login_admin_name&#39;] = $row[&#39;login_name&#39;];

echo "<script type=&#39;text/javascript&#39;>alert('登录成功');setTimeout(function(){location.href='/login_ok.php'}, 500)";
Copy after login

login_ok.php

<?php session_start();
include &#39;php/config.php&#39;;
?>
nbsp;html>


<meta>
<title>留言表单后台登录_科科分享</title>
<link>


<p>
  </p><p>
    </p><p>
      </p><p>
            您好,<?php  echo $_SESSION[&#39;login_admin_name&#39;]?>,<a>退出</a>。
        </p>
      <p>
        </p><h3>您已登录后台中心!</h3>
      
    
  


Copy after login

logout.php

<?php session_start();
unset($_SESSION[&#39;login_admin_id&#39;]);
unset($_SESSION[&#39;login_admin_name&#39;]);
session_destroy();
echo "<script type=&#39;text/javascript&#39;>alert('注销登录成功');setTimeout(function(){location.href='/login.html'}, 500)";
Copy after login

3. Test

Develop a good habit, simply test it once, and then submit the work.
Login page

Record PHP7 message board development background management-login/logout

The page after successful login

Record PHP7 message board development background management-login/logout

4. Summary
Knowledge points of this section Just one session, grasp the usage, and you are not far from the high-end cloud backend.
Remember to use your hands to type code, blindly copying and pasting will not achieve the learning effect~

Related free learning recommendations: php programming (video)

The above is the detailed content of Record PHP7 message board development background management-login/logout. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jianshu.com
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