Home  >  Article  >  Backend Development  >  Example of cookie in php session technology

Example of cookie in php session technology

WBOY
WBOYOriginal
2016-07-25 08:56:231195browse
This article shares an example of using PHP to implement session technology cookies. It is a very simple example and is suitable for reference for getting started with PHP cookies. Friends in need can take a look.

For example, if you want to display the login time, it will prompt you when you log in for the first time, otherwise it will display the time of your last login.

Code:

<?php
    //显示上次登录的时间
    if(!empty($_COOKIE['lastvisit'])){

        echo "您上次登录的时间:".$_COOKIE['lastvisit'];
        //保存一个星期
        setcookie("lastvisit",date("Y-m-d H:i:s"),time()+7*24*3600);
        
    }else{
        echo "欢迎光临。您是第一次登陆";
        setcookie("lastvisit",date("Y-m-d H:i:s"),time()+7*24*3600);
    }
?>


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