Php+ajax Authentication Login Jump Login Implementation method

Source: Internet
Author: User
This article mainly introduces the Php+ajax login jump login Implementation ideas, very simple, the need for small partners can refer to the next

When our users log on to the system, the authentication of the username and password is back-end verified. Moreover, the user login state is also to set the backend, after querying the database, the user name and password is correct, then in the session to store a UUID, each page needs to be judged according to the login status to display the corresponding content, then determine if there is a UUID this session, and UUID is not empty. For example, the login button on the head, the login button is displayed, the user name and avatar are displayed after login, these are the values that determine if there is a UUID (in the implementation, relatively more complex).

Let's take this step again:

    1. Back-end Ajax send user name and password

    2. After the backend receives the user name and password, query the database

    3. If the query fails, a JSON data is returned, for example: {"status": "1", msg: "Username or password is incorrect"}

    4. 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"}

    5. The front end JS receives the returned data, determines the status value, if Status==0, uses the window.location.href to jump; the other status codes are login failures, empty the password box, and let the user re-enter

For example, login successfully jump to the home page, the first page of PHP or Java, you need to determine whether there are UUID in the session

<nav>  <?php if (isset ($_session[' uuid ") &&!empty ($_session[' uuid])):?>    <!-- If a UUID is present, it is not empty, indicating that it is logged-    <a href= "#" > Mosquitoes </a>  <?php else?>    <!--not logged in    - <input type= "button" value= "Login"/>  <?php endif;?></nav>

Summary: The above is the entire content of this article, I hope to be able to help you learn.

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.