Home > Article > Backend Development > Implementation method of php+ajax verification login jump login
This article mainly introduces the idea of php ajax login jump login implementation. It is very simple. Friends in need can refer to it
When our users log in to the system, the user name and password are verified. It's all back-end verified. Moreover, the user login status also needs to be set on the backend. After querying the database, if the username and password are correct, a uuid will be stored in the session. When each page needs to judge and display the corresponding content based on the login status, it will be judged whether there is a uuid session. , and uuid is not empty. For example, the login button in the header displays the login button when not logged in, and displays the username and avatar after logging in. These are all used to determine whether there is a uuid value (in the specific implementation, it is relatively more complicated).
Let’s take care of this step again:
Send the user name and password to the backend ajax
The backend receives the user After the name and password, query the database
If the query fails, a json data will be returned, such as: {"status":"-1", msg:"The user name or password is incorrect" }
If the query is successful, store a value in the session, such as uuid, and then return a json to the front end, such as: {"status":"0", msg:"success "}
After the front-end js receives the returned data, it determines the value of status. If status==0, use window.location.href to jump; other status codes are If the login fails, clear the password box and allow the user to re-enter
. For example, if the login is successful and jumps to the home page, for php or java on the home page, you need to determine whether there is a uuid in the session
<nav> <?php if(isset($_SESSION['uuid']) && !empty($_SESSION['uuid'])):; ?> <!-- 若存在uuid,则不为空,则表示已经登录 --> <a href="#">蚊子</a> <?php else ?> <!-- 没有登录 --> <input type="button" value="登录" /> <?php endif; ?> </nav>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations: Detailed explanation of the usage of final keyword in
php Detailed analysis of usage of this keyword in
Case analysis of advanced features of PHP objects, patterns and practices
##
The above is the detailed content of Implementation method of php+ajax verification login jump login. For more information, please follow other related articles on the PHP Chinese website!