This article mainly introduces the Php+ajax login jump login Implementation ideas, very simple, the need for small partners can refer to the next
When our users log on to the system, the authentication of the username and password is back-end verified. Moreover, the user login state is also to set the backend, after querying the database, the user name and password is correct, then in the session to store a UUID, each page needs to be judged according to the login status to display the corresponding content, then determine if there is a UUID this session, and UUID is not empty. For example, the login button on the head, the login button is displayed, the user name and avatar are displayed after login, these are the values that determine if there is a UUID (in the implementation, relatively more complex).
Let's take this step again:
Back-end Ajax send user name and password
After the backend receives the user name and password, query the database
If the query fails, a JSON data is returned, for example: {"status": "1", msg: "Username or password is incorrect"}
If the query succeeds, store a value in the session, such as a UUID, and then return a JSON to the front end, such as: {"status": "0", msg: "Success"}
The front end JS receives the returned data, determines the status value, if Status==0, uses the window.location.href to jump; the other status codes are login failures, empty the password box, and let the user re-enter
For example, login successfully jump to the home page, the first page of PHP or Java, you need to determine whether there are UUID in the session
<nav> <?php if (isset ($_session[' uuid ") &&!empty ($_session[' uuid])):?> <!-- If a UUID is present, it is not empty, indicating that it is logged- <a href= "#" > Mosquitoes </a> <?php else?> <!--not logged in - <input type= "button" value= "Login"/> <?php endif;?></nav>
Summary: The above is the entire content of this article, I hope to be able to help you learn.