php method to implement login operation: first connect and create the database; then use the layui framework to create the front page; then create the "login.php" file to determine the correctness of the username and password; finally access the file directory Just check the login interface effect.
Recommended: "PHP Video Tutorial"
Naturally, start with the simplest functions. My first task was to perform a login operation, which was actually not as simple as I imagined.
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.
The above is the detailed content of How to implement login operation function in php. For more information, please follow other related articles on the PHP Chinese website!