Home>Article>Daily Programming> PHP cookie implementation method to determine whether the user is logged in (image, text + video)
This article mainly introducesPHP 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 thePHP 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:
After we have logged in successfully, close and refresh the home page again. The following effect will be displayed:
And when we delete the cookie (inspect the element through the f12 shortcut key), it is equivalent to logging out:
After refreshing the browser, you will get the result as shown below:
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 websitePHP 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!