Zikula_Core
[ class tree: Zikula_Core ] [ index: Zikula_Core ] [ all elements ]

Source for file CookieUtil.class.php

Documentation is available at CookieUtil.class.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright Robert Gasch
  6.  * @link http://www.zikula.org
  7.  * @version $Id: CookieUtil.class.php 20486 2006-11-11 16:17:02Z rgasch $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Robert Gasch rgasch@gmail.com
  10.  * @uses generic data utililty class
  11.  * @package Zikula_Core
  12.  */
  13.  
  14. /**
  15.  * CookieUtil
  16.  *
  17.  * @package Zikula_Core
  18.  * @subpackage CookieUtil
  19.  */
  20. class CookieUtil
  21. {
  22.     /**
  23.      * Set a cookie value
  24.      *
  25.      * @author Drak
  26.      * @param string $name name of cookie
  27.      * @param string $value 
  28.      * @param int $expires unix epoch dat for expiry
  29.      * @param string $path 
  30.      * @param string $domain domain must be at least .domain.tld
  31.      * @param bool $secure to set if cookie must only be set over existing https connection
  32.      * @param bool $signed override system setting to use signatures
  33.      * @return bool 
  34.      */
  35.     function setCookie($name$value=''$expires=null$path=null$domain=null$secure=null$signed true)
  36.     {
  37.         if (!$name{
  38.             return pn_exit('setCookie: must specify at least cookie name 'DataUtil::formatForDisplay($name));
  39.         }
  40.  
  41.         if (!is_string($value)) {
  42.             return pn_exit('setCookie: ' DataUtil::formatForDisplay($value' must be a string');
  43.         }
  44.  
  45.         if (pnConfigGetVar('signcookies'&& (!$signed==false))// sign the cookie
  46.             $value SecurityUtil::signData($value);
  47.         }
  48.  
  49.         return setcookie($name$value$expires$path$domain$secure);
  50.     }
  51.  
  52.     /**
  53.      * Get a cookie
  54.      *
  55.      * @author Drak
  56.      * @param string $name name of cookie
  57.      * @param bool $signed override system setting to use signatures
  58.      * @param bool $default default value
  59.      * @return mixed cookie value as string or bool false
  60.      */
  61.     function getCookie($name$signed=true$default='')
  62.     {
  63.         $cookie FormUtil::getPassedValue($name$default'COOKIE');
  64.         if (pnConfigGetVar('signcookies'&& (!$signed==false)){
  65.             return SecurityUtil::checkSignedData($cookie);
  66.         }
  67.  
  68.         return $cookie;
  69.     }
  70.  
  71.     /**
  72.      * Delete given cookie
  73.      * can be called multiple times, but must be other output is sent to browser.
  74.      *
  75.      * @author Drak
  76.      * @param string $name nmame of cookie
  77.      * @return bool 
  78.      */
  79.     function deleteCookie($name)
  80.     {
  81.         return CookieUtil::setCookie($name''time());
  82.     }
  83. }

Documentation generated on Fri, 18 Jul 2008 21:44:04 +0200 by phpDocumentor 1.4.1