Home>Article>Backend Development> Relevant code analysis for php to implement login function

Relevant code analysis for php to implement login function

jacklove
jacklove Original
2018-06-11 22:16:06 1901browse

Naturally, I started with the simplest function. My first task was to perform a login operation, but it was not as simple as I thought.

1. The first thing is to connect and create the database.

I wrote this part in model.php

$userName='root'; $passWord=''; $host='localhost'; $dataBase='login'; //创建连接 $conn=mysqli_connect($host,$userName,$passWord,$dataBase);

2. To write the front-end page, in order to become proficient in the front-end framework, I used The layui framework makes the interface, and there is a js code in front of it to determine whether the username and password input is empty

      注册登录 

注册登录系统


3.login.php is used to determine the correctness of the username and password. I read about this on the Internet There are many methods, all kinds of. Before I encountered any obstacles, I decided to use a simple form first, which is to use SQL statements to query the result set of user name and password. If the result set is empty, the user does not exist.

alert('密码错误,请重新输入');location='login.html'"; } else{ echo ""; };

4. File directory

5. Effect



6. Summary

Overall it is not particularly difficult because the function is very simple. The next task is to add the registration function and verification code function.

This article explains the relevant code of php to implement the login function. For more related content, please pay attention to the php Chinese website.

Related recommendations:
Explanation of JavaScript-related content

Explanation of the basics of HTML

$.ajax php practical tutorial automatically loads more articles when you pull down the principle explanation

The above is the detailed content of Relevant code analysis for php to implement login function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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