Heim  >  Artikel  >  php教程  >  php浏览记录 COOKIE

php浏览记录 COOKIE

PHP中文网
PHP中文网Original
2016-05-25 17:13:371032Durchsuche

[PHP]代码 

/* 记录浏览历史 */
if (!empty($_COOKIE['history']))
{
    if(stripos($_COOKIE['history'].',',$goods_id.',')===false){
        
        $history = explode(',', $_COOKIE['history']);

        array_unshift($history, $goods_id); //入栈
        
    
        while (count($history) > 5) //大于容器容量
        {
            array_pop($history); //出栈
        }
    
        setcookie('history', implode(',', $history), gmtime() + 3600 * 24 * 30); 
    }
}
else
{
    setcookie('history', $goods_id, gmtime() + 3600 * 24 * 30);
}

                   

                   

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP检测用户语言Nächster Artikel:PHP 文件上传代码