Home> php教程> php手册> body text

ajax login jump login implementation

伊谢尔伦
Release: 2016-12-10 09:33:59
Original
2017 people have browsed it

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

Copy after login


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 Recommendations
    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!