Php + ajax login jump login Implementation ideas, ajax jump
When our users log on to the system, the user name and password are verified by the backend. In addition, the user logon status must be set at the backend. After the database is queried, the user name and password are correct, and a uuid is stored in the session, when the corresponding content is displayed on each page based on the logon status, the system determines whether the session uuid exists and the uuid is not empty. For example, for the login button in the header, the login button is displayed in the "not logged on" status, and the user name and avatar are displayed after the login, which are used to determine whether the uuid value exists (in the specific implementation, ).
Let's take another look at this step:
- Send username and password to backend ajax
- After the backend receives the user name and password, it queries the database.
- If the query fails, a json data is returned, such as: {"status": "-1", msg: "incorrect user name or password "}
- If the query is successful, a value, such as uuid, is stored in the session and a json value is returned to the front-end, for example, {"status": "0", msg: "success "}
- After receiving the returned data, the front-end js determines the status value. If status = 0, the window is used. location. href jump; other status codes are logon failures. Clear the Password box and ask the user to re-enter
For example, if a user successfully logs on to the home page, the php or java on the home page needs to determine whether the session has a uuid.
<Nav> <? Php if (isset ($ _ SESSION ['uuid']) &! Empty ($ _ SESSION ['uuid']):;?> <! -- If uuid exists, it is not empty, it indicates that you have logged on. --> <a href = "#"> mosquito </a> <? Php else?> <! -- No Logon --> <input type = "button" value = "Logon"/> <? Php endif;?> </Nav>