search
Homephp教程php手册ajax login jump login implementation

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

<nav>
    <?php if(isset($_SESSION[&#39;uuid&#39;]) && !empty($_SESSION[&#39;uuid&#39;])):;  ?>
        <!-- 若存在uuid,则不为空,则表示已经登录 -->
        <a href="#">蚊子</a>
    <?php else ?>
        <!-- 没有登录 -->
        <input type="button" value="登录" />
    <?php endif; ?>
</nav>


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.