When our user is logged on to the system, the user name and password verification are backend authenticated. Moreover, the user login status is also to the backend settings, after querying the database, the user name and password is correct, then stored in the session of the UUID, each page needs to be judged according to the status of login to display the corresponding content, then determine whether there is a UUID this session, and the UUID is not empty For example, the head of the login button, in the not logged in state is to display the login button, after the login to display the user name and Avatar, these are to determine whether there is a UUID value (specifically implemented, relatively more complex).
Let's take this step again:
- Back-end Ajax sending username and password
- After the backend receives the username and password, the query database
- If the query fails, returns a JSON data such as: {"status": "1", msg: "Incorrect username or password"}
- 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 received the returned data, judge the value of status, if status==0, then use window.location.href to jump; Other status codes are login failures, empty password boxes, let users re-enter
For example, login successfully jump to the home page, the first page of PHP or Java, you need to determine whether there is a UUID session
<nav>
<?php if (isset ($_session[' uuid ')) &&!empty ($_session[' uuid ')):?>
<!-- If a UUID exists, it is not NULL, indicating that the-->
<a href= "#" > Mosquito </a>
<?php Else?>
<!--not logged in-->
<input type= "button" value= "Login"/>
<?php endif;?>
</nav>