Home  >  Article  >  Daily Programming  >  PHP cookie implementation method to determine whether the user is logged in (image, text + video)

PHP cookie implementation method to determine whether the user is logged in (image, text + video)

藏色散人
藏色散人Original
2018-10-18 15:59:144943browse

This article mainly introduces PHP cookie implementation method to determine whether the user is logged in.

Basic knowledge points related to cookies in PHP, we have discussed in the previous article [How to record and delete variables in cookies in PHP? ] and [PHP cookie implementation method of recording user login information] have been introduced in detail for everyone.

Then the content of this article will be introduced based on the previous cookie-related knowledge points. Friends in need can choose to refer to it.

Below we will use a simple example to introduce the PHP cookie implementation method to determine whether the user is logged in.

这里是主页";
@$name = $_COOKIE['username'];
echo $_COOKIE['username'];
if ($name) {
    echo "";
}else{
    echo "";
    echo "如果跳转失败请点击跳转~~";
    header("Refresh:1;url=login.html");
}

Here we simply use js to simply write a prompt pop-up window to determine whether the user is logged in.

When we log in for the first time, the result after successfully jumping to the main page is as follows:

PHP cookie implementation method to determine whether the user is logged in (image, text + video)

After we have logged in successfully, close and refresh the home page again. The following effect will be displayed:

PHP cookie implementation method to determine whether the user is logged in (image, text + video)

And when we delete the cookie (inspect the element through the f12 shortcut key), it is equivalent to logging out:

PHP cookie implementation method to determine whether the user is logged in (image, text + video)

After refreshing the browser, you will get the result as shown below:

PHP cookie implementation method to determine whether the user is logged in (image, text + video)

Re-login will be displayed here.

This article is an introduction to the method of using PHP cookie to determine whether the user is logged in. It is also very simple. I hope it will be helpful to friends in need!

If you want to know more about PHP, you can follow the PHP Chinese website PHP Video Tutorial, everyone is welcome to refer to and learn!

The above is the detailed content of PHP cookie implementation method to determine whether the user is logged in (image, text + video). For more information, please follow other related articles on the PHP Chinese website!

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