Php + ajax login jump login Implementation ideas, ajax jump

Source: Internet
Author: User

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:

  1. Send username and password to backend ajax
  2. After the backend receives the user name and password, it queries the database.
  3. If the query fails, a json data is returned, such as: {"status": "-1", msg: "incorrect user name or password "}
  4. 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 "}
  5. 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.