Implementation method of php+ajax verification login jump login

墨辰丷
Release: 2023-03-29 09:18:02
Original
2132 people have browsed it

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:

  1. Send the user name and password to the backend ajax

  2. The backend receives the user After the name and password, query the database

  3. If the query fails, a json data will be returned, such as: {"status":"-1", msg:"The user name or password is incorrect" }

  4. 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 "}

  5. 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[&#39;uuid&#39;]) && !empty($_SESSION[&#39;uuid&#39;])):; ?>
    <!-- 若存在uuid,则不为空,则表示已经登录 -->
    <a href="#">蚊子</a>
  <?php else ?>
    <!-- 没有登录 -->
    <input type="button" value="登录" />
  <?php endif; ?>
</nav>
Copy after login

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!