<?php
namespace Core;
/**
*
* @author chenyuwen
*
*/
class Cookie
{
/**
* cookie的配置
* @var array
*/
private static $config = array ('lifetime' => NULL, 'path' => NULL, 'domain' => NULL, 'secure' => NULL, 'httponly' => NULL );
/**
* 配置cookie参数
*
* @param array $config
*/
public static function set_cookie_params($config = array())
{
foreach ( self::$config as $key => $val )
{
if (isset ( $config [$key] ))
{
self::$config [$key] = $config [$key];
}
}
}
/**
* 设置cookie
*
* @param $key string cookie的键
*
* @param $value mixed cookie的值
*/
public static function set($name, $value)
{
setcookie ( $name, $value, self::$config ['lifetime'], self::$config ['path'], self::$config ['domain'], self::$config ['secure'], self::$config ['httponly'] );
}
/**
* 获取cookie
*
* @return mixed
*/
public static function get($name, $default = NULL)
{
if (isset ( $_COOKIE [$name] ))
{
return $_COOKIE [$name];
}
return $default;
}
}
转载于:https://my.oschina.net/yuwenc/blog/310586