Show Source00001 <?php
00040 class zCookie extends zCore{
00041 function zCookie(){
00042 $this->__construct();
00043 }
00044 function __construct(){
00045 zDef::set('Z_COOKIE_EXPIRE', Z_COOKIE_EXPIRE);
00046 zDef::set('Z_COOKIE_SECURE', Z_COOKIE_SECURE);
00047 zDef::set('Z_COOKIE_HTTPONLY', Z_COOKIE_HTTPONLY);
00048 }
00060 function getEncrypted($key=null){
00061 if(is_array($key)){
00062 perror('zCookie::getEncrypted() doesn\'t accept array');
00063 exit;
00064 }
00065 if($key != null){
00066 zLogger::debug("Getting Value of Encrypted Key $key", 'rom.cookie');
00067 if(isset($_COOKIE[$key])){
00068 return zCrypt::decrypt($_COOKIE[$key], true);
00069 }else{
00070 perror('<code>zigmoyd.Cookie.get</code><br />Trying to get non existing Cookie Variable `'.$key.'`');
00071 }
00072 }else{
00073 return zCrypt::decrypt($_COOKIE, true);
00074 }
00075 return false;
00076 }
00094 function setEncrypted($key, $val, $expire=null, $path='', $domain=null, $secure=null, $httpOnly=null){
00095 if(is_null($expire))$expire = zDef::get('Z_COOKIE_EXPIRE');
00096 if(is_null($secure))$expire = zDef::get('Z_COOKIE_SECURE');
00097 if(is_null($httpOnly))$expire = zDef::get('Z_COOKIE_HTTPONLY');
00098 zLogger::debug("Setting Value of Encrypted Key:$key Value:$val Expire: $expire, Path: $path Domain: $domain Secure: $secure HTTPOnly: $httpOnly", 'rom.cookie');
00099 return setcookie($key, zCrypt::encrypt($val, true), (int)$expire, (string)$path, $domain, $secure);
00100 }
00108 function getPlain($key=null){
00109 if(is_array($key)){
00110 perror('zCookie::getPlain() doesn\'t accept array');
00111 }
00112 if($key != null){
00113 zLogger::debug("Getting Value of Key $key", 'rom.cookie');
00114 if(isset($_COOKIE[$key])){
00115 return $_COOKIE[$key];
00116 }else{
00117 perror('<code>zigmoyd.Cookie.get</code><br />Trying to get non existing Cookie Variable `'.$key.'`');
00118 }
00119 }else{
00120 return $_COOKIE;
00121 }
00122 return false;
00123 }
00137 function setPlain($key, $val, $expire=0, $path='', $domain=null, $secure=null, $httpOnly=null){
00138 if(is_null($expire))$expire = zDef::get('Z_COOKIE_EXPIRE');
00139 if(is_null($secure))$expire = zDef::get('Z_COOKIE_SECURE');
00140 if(is_null($httpOnly))$expire = zDef::get('Z_COOKIE_HTTPONLY');
00141 zLogger::debug("Setting Value of Key:$key Value:$val Expire: $expire, Path: $path Domain: $domain Secure: $secure HTTPOnly: $httpOnly", 'rom.cookie');
00142 return setcookie($key, $val, (int)$expire, (string)$path, $domain, $secure);
00143 }
00157 function setRaw($key, $val, $expire=0, $path=null, $domain=null, $secure=null, $httpOnly=null){
00158 if(is_null($expire))$expire = zDef::get('Z_COOKIE_EXPIRE');
00159 if(is_null($secure))$expire = zDef::get('Z_COOKIE_SECURE');
00160 if(is_null($httpOnly))$expire = zDef::get('Z_COOKIE_HTTPONLY');
00161 zLogger::debug("Setting Value of Raw Key:$key Value:$val Expire: $expire, Path: $path Domain: $domain Secure: $secure HTTPOnly: $httpOnly", 'rom.cookie');
00162 return setrawcookie($key, $val, $expire, $path, $domain, $secure, $httpOnly);
00163 }
00170 function remove($key=null){
00171 if($key == null || !is_string($key)){
00172 perror("<code>zCookie::remove()</code><br />You must provide which key to delete and that argumnt must be a string to zCookie::remove() e.g. it accepts 1 argumnt");return false;
00173 return false;
00174 }
00175 if(!zCookie::keyExists($key)){
00176 perror("<code>zCookie::remove()</code><br />zCookie::remove() failed to remove key $key from Cookie as it doesn't exist");return false;
00177 return false;
00178 }else{
00179 zLogger::debug("Removing Key $key", 'rom.cookie');
00180 setcookie($key, "", time()-1);
00181 unset($_COOKIE[$key]);
00182 return true;
00183 }
00184 }
00191 function keyExists($key=null){
00192 if($key == null || !is_string($key)){
00193 perror("<code>zCookie::keyExists()</code><br />You must provide which key to delete and that argumnt must be a string to zCookie::keyExists() e.g. it accepts 1 argumnt");return false;
00194 return false;
00195 }
00196 if(!isset($_COOKIE[$key])){
00197 zLogger::debug("zCookie::keyExists() says Key $key Doesn't exist", 'rom.cookie');
00198 return false;
00199 }else{
00200 zLogger::debug("zCookie::keyExists() says Key $key exists", 'rom.cookie');
00201 return true;
00202 }
00203 }
00212 function __call($methodName, $args, &$return){
00213 switch(true){
00223 case (preg_match('~setEncrypted(\w+)~i', $methodName, $m) >= 1):
00224 $return = zCookie::setEncrypted(strtolower($m[1]), $args[0]);
00225 break;
00234 case (preg_match('~getEncrypted(\w+)~i', $methodName, $m) >= 1):
00235 $return = zCookie::getEncrypted(strtolower($m[1]), $args[0]);
00236 break;
00246 case (preg_match('~set(\w+)~i', $methodName, $m) >= 1):
00247 $return = zCookie::setPlain(strtolower($m[1]), $args[0]);
00248 break;
00257 case (preg_match('~get(\w+)~i', $methodName, $m) >= 1):
00258 $return = zCookie::getPlain(strtolower($m[1]));
00259 break;
00260 default:
00261 perror("<code>zigtmoyd.cookie.$methodName()</code><br />no Such method in zCookie Class");
00262 }
00263 return true;
00264 }
00265 }
00266 if(function_exists('overload'))overload('zCookie');
00268 ?>