/ Published in: PHP
Easy and lazy way to use cookie in PHP5
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class Cookie { var $__setting; function __construct($name = 'FuseLogic',$live = 31104000) { $this->__setting = new open(); $this->__setting->name = $name; $this->__setting->space = '___'; $this->setDomain(); $this->setPath(); $this->setLive($live); { foreach($_COOKIE as $k =>$v) { if($temp[0] == $this->__setting->name) { $this->__setting->_cookies[$k] = $v; } } } } function setDomain($domain = '') { $this->__setting->domain = $domain; } function setLive($time = 3600) { $this->__setting->live = (int) $time; } function setPath($path = '/') { $this->__setting->path = $path; } function name($name = null) { return $this->__setting->name.$this->__setting->space.$name; } public function __get($name) { return $this->__setting->_cookies[$name]; } public function __set($name,$value) { $this->__setting->_cookies[$name] = $value; $name = $this->name($name); $_COOKIE[$name] = $value; if($value == null) { }else { } } public function __isset($name) { } function clean() { foreach($this->__setting->_cookies as $name => $value) { $name = $this->name($name); @$_COOKIE[$name] = null; } } function cleanAll() { foreach($_COOKIE as $name => $value) { } } function toArray() { return $this->__setting->_cookies; } function fromArray($a = null) { { foreach($a as $k => $v ) $this->$k = $v; } } }