When our users log in to the system, the username and password are verified by the backend. 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 go through this step again:
Send the username and password to the backend ajax
After the backend receives the username and password, query the database
If the query fails, a json data will be returned, such as: {"status" :"-1", msg:"The username 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 login failures. Clear the password box and let the user re-enter
For example, if the login is successful and jumps to the homepage, php or java on the homepage needs to determine whether there is a uuid in the session