Posted By

mscribellito on 12/30/10


Tagged

class php cookie manager manipulation


Versions (?)

Cookie Class


 / Published in: PHP
 

  1. class Cookie {
  2.  
  3. public static $expiration = 0;
  4.  
  5. public static $path = '/';
  6.  
  7. public static $domain = NULL;
  8.  
  9. public static $secure = FALSE;
  10.  
  11. public static $httponly = FALSE;
  12.  
  13. public static final function write($name = '', $value = '', $expiration = NULL) {
  14.  
  15. if ($expiration === NULL) $expiration = self::$expiration;
  16.  
  17. if ($expiration !== 0) $expiration += time();
  18.  
  19. setcookie($name, $value, $expiration, self::$path, self::$domain, self::$secure, self::$httponly);
  20.  
  21. }
  22.  
  23. public static final function read($name = '', $default = NULL) {
  24.  
  25. if ( ! isset($_COOKIE[$name])) return $default;
  26.  
  27. return $_COOKIE[$name];
  28.  
  29. }
  30.  
  31. public static final function delete($name = '') {
  32.  
  33. unset($_COOKIE[$name]);
  34.  
  35. self::write($name, NULL, -86400);
  36.  
  37. }
  38.  
  39. }

Report this snippet  

You need to login to post a comment.