


Record PHP7 message board development background management-login/logout
php7 tutorialThe column introduces how to develop a message board
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 $_SESSION
The 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 id="留言表单后台登录">留言表单后台登录</h3> <h5 id="span-FEEDBACK-span"><span>FEEDBACK</span></h5> <p> </p>
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;}
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='管理员数据表';
login.php
<?php include 'config.php'; $login_name = !empty($_POST['login_name'])? addslashes(strip_tags($_POST['login_name'])):''; $password = !empty($_POST['password'])?addslashes(strip_tags($_POST['password'])):''; // 简单验证一下提交的数据 if (empty($login_name) || empty($password)) { exit('请输入登录信息!'); } $sql = "SELECT * FROM admin WHERE `login_name` = '{$login_name}' LIMIT 1"; $result = mysqli_query($mysqli, $sql); $row = mysqli_fetch_array($result); if (empty($row)) { exit('账号密码错误!'); } $res_password = $row['password']; $password = md5(md5($password) . $row['salt']); // 密码不匹配 if ($res_password != $password) { exit('账号密码错误!'); // 为了程序的安全,这里不必具体提示密码错误,告知用户账号或密码错误即可。 } // 登录成功,保存登录信息,一般都用session进行处理 session_start(); $_SESSION['login_admin_id'] = $row['id']; $_SESSION['login_admin_name'] = $row['login_name']; echo "<script type='text/javascript'>alert('登录成功');setTimeout(function(){location.href='/login_ok.php'}, 500)";
login_ok.php
<?php session_start(); include 'php/config.php'; ?> nbsp;html> <meta> <title>留言表单后台登录_科科分享</title> <link> <p> </p><p> </p><p> </p><p> 您好,<?php echo $_SESSION['login_admin_name']?>,<a>退出</a>。 </p> <p> </p><h3 id="您已登录后台中心">您已登录后台中心!</h3>
<?php session_start(); unset($_SESSION['login_admin_id']); unset($_SESSION['login_admin_name']); session_destroy(); echo "<script type='text/javascript'>alert('注销登录成功');setTimeout(function(){location.href='/login.html'}, 500)";
3. Test
Develop a good habit, simply test it once, and then submit the work.
Login page
The page after successful login
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to install the mongo extension in php7.0: 1. Create the mongodb user group and user; 2. Download the mongodb source code package and place the source code package in the "/usr/local/src/" directory; 3. Enter "src/" directory; 4. Unzip the source code package; 5. Create the mongodb file directory; 6. Copy the files to the "mongodb/" directory; 7. Create the mongodb configuration file and modify the configuration.

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

In php5, we can use the fsockopen() function to detect the TCP port. This function can be used to open a network connection and perform some network communication. But in php7, the fsockopen() function may encounter some problems, such as being unable to open the port, unable to connect to the server, etc. In order to solve this problem, we can use the socket_create() function and socket_connect() function to detect the TCP port.

Common solutions for PHP server environments include ensuring that the correct PHP version is installed and that relevant files have been copied to the module directory. Disable SELinux temporarily or permanently. Check and configure PHP.ini to ensure that necessary extensions have been added and set up correctly. Start or restart the PHP-FPM service. Check the DNS settings for resolution issues.

How to install and deploy php7.0: 1. Go to the PHP official website to download the installation version corresponding to the local system; 2. Extract the downloaded zip file to the specified directory; 3. Open the command line window and go to the "E:\php7" directory Just run the "php -v" command.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Compared with PHP7, PHP8 has some advantages and improvements in terms of performance, new features and syntax improvements, type system, error handling and extensions. However, choosing which version to use depends on your specific needs and project circumstances. Detailed introduction: 1. Performance improvement, PHP8 introduces the Just-in-Time (JIT) compiler, which can improve the execution speed of the code; 2. New features and syntax improvements, PHP8 supports the declaration of named parameters and optional parameters, making functions Calling is more flexible; anonymous classes, type declarations of properties, etc. are introduced.
