<?php
class Cookie implements ArrayAccess {
public function offsetSet($offset, $value) {
setcookie($offset, $value);
}
public function offsetGet($offset) {
return $_COOKIE[$offset];
}
public function offsetUnset($offset) {
setcookie($offset, null, time()-1);
}
public function offsetExists($offset)
{
return isset($_COOKIE[$offset]);
}
}
$cookie = new Cookie;
// 读取Cookie
print $cookie["username"];
// 写入Cookie
$cookie["passwd"] = "123abc";
Notice: Undefined index: username in /in/XHZIl on line 8
Warning: Cannot modify header information - headers already sent by (output started at /in/XHZIl:8) in /in/XHZIl on line 4
Output for 5.2.3 - 5.2.17
Notice: Undefined index: username in /in/XHZIl on line 8
Warning: Cannot modify header information - headers already sent by (output started at /in/XHZIl:8) in /in/XHZIl on line 4