Home>Article>Backend Development> Relevant code analysis for php to implement login function
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
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!