Public Member Functions | |
zSession () | |
__construct () | |
started () | |
Is session started. | |
start () | |
Starts the Session. | |
getEncrypted ($key=null) | |
Get value of an encrypted session variable. | |
setEncrypted ($key, $val) | |
Set value of an session variable in encrypted format. | |
getPlain ($key=null) | |
get's value of a Plain(UnEncrypted) session data. | |
setPlain ($key, $val) | |
Set's Session data as Plain Text(Un Encrypted) Stiores Session Data in Unencrypted Format so you need to invoke zSession::getPlain() to retrive its value. | |
remove ($key=null) | |
Removes a Session Variable. | |
keyExists ($key=null) | |
Checks wheather a Key exists with the name provided or not. | |
commit () | |
Stores the session Data Immedietly. | |
regenerateId ($delOldFlag=true) | |
Regenarates Session ID. | |
cookieParams ($lifeTime=null, $path=null, $domain=null, $secure=null, $httpOnly=null) | |
get/set the session cookie parameters. | |
Id ($id=null) | |
get/set the Current session's Id | |
Name ($sessionName=null) | |
get/set the name of the current session | |
rollBack ($savePointName=null) | |
Rolls back the session data to the previous stage or to a Specified save point. | |
savePoint ($savePointName) | |
sets a savepoint | |
Data Fields | |
$bak = array() | |
$savePoint = array() |
zSession Class can be used with its static methods e.g. zSession::methodName() like zSession::start() or zSession::started() etc.. zSession can also be used from its Instance in ROM. which can be found on $request->session through $request Global Variable. and as ROM engine is embeded into Controller you can also use $this->request->session to call a static/non-static method from the Instance. zSession Class holds several static and non-static methods static methods can be called without an instance where as you must use ROM engine to call a non-static method. You can also use PHP's $_SESSION with it however this is more structured way. setting and getting variables through $_SESSION ould work like zSession::setPlain() and zSession::getPlain(). It also Supports Magic Methods like getName(), setName('Foo') etc..
Definition at line 40 of file session_handler.php.
zSession::__construct | ( | ) |
Reimplemented from zCore.
Definition at line 59 of file session_handler.php.
Referenced by zSession().
00059 { 00060 global $_SESSION; 00061 parent::__construct(); 00062 if(!defined('DELETE_OLD_SESSION'))define('DELETE_OLD_SESSION', true); 00063 if(!defined('KEEP_OLD_SESSION'))define('KEEP_OLD_SESSION', false); 00064 $this->bak = $_SESSION; 00065 }
zSession::zSession | ( | ) |
Definition at line 56 of file session_handler.php.
References __construct().
00056 { 00057 $this->__construct(); 00058 }
zSession::started | ( | ) |
Is session started.
checks wheather the session has been started or not. Returns true if sesssion has been already started else returns false.
Definition at line 73 of file session_handler.php.
References zLogger::debug().
Referenced by commit(), cookieParams(), Id(), regenerateId(), and start().
00073 { 00074 if(isset($_SESSION)){ 00075 zLogger::debug("zSession::start() returning true as session has been started", 'rom.session'); 00076 return true; 00077 }else{ 00078 zLogger::debug("zSession::start() returning false as session has not been started yet", 'rom.session'); 00079 return false; 00080 } 00081 }
zSession::start | ( | ) |
Starts the Session.
Starts the Session if already not started. It doesn't start the Session if it already has been started so that session is started only once. By default Zigmoyd starts Session automatically at the begening. Hoe you can change this behavior (But not recomended) by changing the value of Z_SESSION_AUTO_START in etc/zig.ini.php of your Project.
Definition at line 93 of file session_handler.php.
References zLogger::debug(), and started().
Referenced by zCaptcha::captcha(), commit(), cookieParams(), getEncrypted(), getPlain(), Id(), regenerateId(), setEncrypted(), and setPlain().
00093 { 00094 if(!session_id() && !headers_sent() && !zSession::started()){ 00095 session_name(Z_SESSION_NAME); 00096 zLogger::debug("Starting session", 'rom.session'); 00097 session_start(); 00098 }else{ 00099 zLogger::debug("session already started", 'rom.session'); 00100 } 00101 }
zSession::getEncrypted | ( | $ | key = null |
) |
Get value of an encrypted session variable.
Zigmoyd is able to set/get session data in encrypted format using your current Encryption settings. So If you set a session data in Encrypted format using zSession::setEncrypted() You need to call zSession::getEncrypted() to retrive its value.
$key | string Name of Session variable |
Definition at line 113 of file session_handler.php.
References zLogger::debug(), zCrypt::decrypt(), perror(), and start().
00113 { 00114 zLogger::debug("Getting value of Encrypted Key $key", 'rom.session'); 00115 zSession::start(); 00116 if(is_array($key)){ 00117 perror('zSession::get() doesn\'t accept array'); 00118 } 00119 if($key != null){ 00120 if(isset($_SESSION[$key])){ 00121 return zCrypt::decrypt($_SESSION[$key], true); 00122 }else{ 00123 perror('<code>zigmoyd.session.get</code><br />Trying to get non existing session Variable `'.$key.'`'); 00124 } 00125 }else{ 00126 return zCrypt::decrypt($_SESSION, true); 00127 } 00128 return false; 00129 }
zSession::setEncrypted | ( | $ | key, | |
$ | val | |||
) |
Set value of an session variable in encrypted format.
Zigmoyd is able to set/get session data in encrypted format using your current Encryption settings. So you can set a session data in Encrypted format using zSession::setEncrypted() You need to call zSession::getEncrypted() to retrive its value.
$key | string Name of Session variable | |
$val | mixed value of that Session variable |
Definition at line 142 of file session_handler.php.
References $val, zLogger::debug(), zCrypt::encrypt(), and start().
00142 { 00143 zLogger::debug("Setting Encrypted value $val of Key $key", 'rom.session'); 00144 zSession::start(); 00145 if($_SESSION[$key] = zCrypt::encrypt($val, true)){return true;} 00146 return false; 00147 }
zSession::getPlain | ( | $ | key = null |
) |
get's value of a Plain(UnEncrypted) session data.
returns value of a Session data which is set using zSession::setPlain() method or set as unEncrypted text through some other way e.g. $_SESSION etc..
$key | string session variable Name |
Definition at line 155 of file session_handler.php.
References zLogger::debug(), perror(), and start().
00155 { 00156 zLogger::debug("Getting value of Key $key", 'rom.session'); 00157 zSession::start(); 00158 if(is_array($key)){ 00159 perror('zSession::getPlain() doesn\'t accept array'); 00160 } 00161 if($key != null){ 00162 if(isset($_SESSION[$key])){ 00163 return $_SESSION[$key]; 00164 }else{ 00165 perror('<code>zigmoyd.session.get</code><br />Trying to get non existing session Variable `'.$key.'`'); 00166 } 00167 }else{ 00168 return $_SESSION; 00169 } 00170 return false; 00171 }
zSession::setPlain | ( | $ | key, | |
$ | val | |||
) |
Set's Session data as Plain Text(Un Encrypted) Stiores Session Data in Unencrypted Format so you need to invoke zSession::getPlain() to retrive its value.
$key | string Session Variable Name | |
$val | mixed Session variable Value |
Definition at line 180 of file session_handler.php.
References $val, zLogger::debug(), and start().
Referenced by rollBack().
00180 { 00181 zLogger::debug("Setting value $val of Key $key", 'rom.session'); 00182 zSession::start(); 00183 if($_SESSION[$key] = $val){return true;} 00184 return false; 00185 }
zSession::remove | ( | $ | key = null |
) |
Removes a Session Variable.
removes a session Variable doesn't matter if its encrypted or not.
$key | string Session variable name |
Definition at line 193 of file session_handler.php.
References zLogger::debug(), keyExists(), and perror().
00193 { 00194 zLogger::debug("removing Key $key", 'rom.session'); 00195 if($key == null || !is_string($key)){ 00196 perror("<code>zSession::remove()</code><br />You must provide which key to delete and that argumnt must be a string to zSession::remove() e.g. it accepts 1 argumnt");return false; 00197 return false; 00198 } 00199 if(!zSession::keyExists($key)){ 00200 perror("<code>zSession::remove()</code><br />zSession::remove() failed to remove key $key from session as it doesn't exist");return false; 00201 return false; 00202 }else{ 00203 unset($_SESSION[$key]); 00204 return true; 00205 } 00206 }
zSession::keyExists | ( | $ | key = null |
) |
Checks wheather a Key exists with the name provided or not.
Checks wheather or not a Session Variable exists with the provided key Name. Returns boolean value. e.g. true if it exists false otherwise
$key | string Session Variable Name |
Definition at line 214 of file session_handler.php.
References perror().
Referenced by remove().
00214 { 00215 if($key == null || !is_string($key)){ 00216 perror("<code>zSession::keyExists()</code><br />You must provide which key to Check and that argumnt must be a string to zSession::keyExists() e.g. it accepts 1 argumnt"); 00217 return false; 00218 } 00219 return isset($_SESSION[$key]); 00220 }
zSession::commit | ( | ) |
Stores the session Data Immedietly.
Session data is usually stored after your script terminated. However if you invoke zSession::commit() it will try to do that immedietly. e.g. same as session_write_close() standared PHP function
Definition at line 226 of file session_handler.php.
References zLogger::debug(), start(), and started().
00226 { 00227 zLogger::debug("Commiting session data to the server", 'rom.session'); 00228 if(!zSession::started())zSession::start(); 00229 session_write_close(); 00230 }
zSession::regenerateId | ( | $ | delOldFlag = true |
) |
Regenarates Session ID.
replace the current session id with a new one, and keep the current session information
$delOldSession | boolean Deleta Old session Data or not ? boolean value |
Definition at line 238 of file session_handler.php.
References zLogger::debug(), start(), and started().
00238 { 00239 zLogger::debug("Regenarating session ID", 'rom.session'); 00240 if(!zSession::started())zSession::start(); 00241 return session_regenerate_id($delOldFlag); 00242 }
zSession::cookieParams | ( | $ | lifeTime = null , |
|
$ | path = null , |
|||
$ | domain = null , |
|||
$ | secure = null , |
|||
$ | httpOnly = null | |||
) |
get/set the session cookie parameters.
Works like session_set_cookie_params() standared PHP function.
$lifeTime | int | |
$path | string | |
$domain | string | |
$secure | boolean | |
$httpOnly | boolean |
Definition at line 254 of file session_handler.php.
References start(), and started().
00254 { 00255 if(!zSession::started())zSession::start(); 00256 if(is_null($lifeTime) && is_null($path) && is_null($domain) && is_null($secure) && is_null($httpOnly)){ 00257 return session_get_cookie_params(); 00258 }else{ 00259 $currentParams = session_get_cookie_params(); 00260 if(is_null($lifeTime))$lifeTime = $currentParams['lifetime']; 00261 if(is_null($path))$path = $currentParams['path']; 00262 if(is_null($domain))$domain = $currentParams['domain']; 00263 if(is_null($secure))$secure = $currentParams['secure']; 00264 if(is_null($httpOnly))$httpOnly = $currentParams['httponly']; 00265 session_set_cookie_params($lifeTime, $path, $domain, $secure, $httpOnly); 00266 } 00267 }
zSession::Id | ( | $ | id = null |
) |
get/set the Current session's Id
$id | string |
Definition at line 274 of file session_handler.php.
References zLogger::debug(), start(), and started().
00274 { 00275 if(!zSession::started())zSession::start(); 00276 if(is_null($id)){ 00277 $sesId = session_id(); 00278 }else{ 00279 $sesId = (strlen(session_id($id)) >= 1); 00280 } 00281 zLogger::debug("Returning session Id $sesId", 'rom.session'); 00282 return $sesId; 00283 }
zSession::Name | ( | $ | sessionName = null |
) |
get/set the name of the current session
$sessionName | string |
Definition at line 290 of file session_handler.php.
References zLogger::debug().
00290 { 00291 if(!is_null($sessionName)){ 00292 $sesName = (strlen(session_name($sessionName)) >= 1); 00293 }else{ 00294 $sesName = session_name(); 00295 } 00296 zLogger::debug("Returning session Name $sesName", 'rom.session'); 00297 return $sesName; 00298 }
zSession::rollBack | ( | $ | savePointName = null |
) |
Rolls back the session data to the previous stage or to a Specified save point.
$savePointName | string SavePoint Name to which you want to restore |
Definition at line 306 of file session_handler.php.
References $val, savePoint(), and setPlain().
00306 { 00307 if(is_null($savePointName)){ 00308 foreach($this->bak as $key => $val){ 00309 zSession::setPlain($key, $val); 00310 } 00311 }else{ 00312 foreach($this->savePoint[$savePointName] as $key => $val){ 00313 zSession::setPlain($key, $val); 00314 } 00315 } 00316 }
zSession::savePoint | ( | $ | savePointName | ) |
sets a savepoint
$savePointName | string Savepoint Name where to backup the Current Session Data |
Definition at line 323 of file session_handler.php.
Referenced by rollBack().
00323 { 00324 $this->savePoint[$savePointName] = $_SESSION; 00325 }
zSession::$bak = array() |
Definition at line 47 of file session_handler.php.
zSession::$savePoint = array() |
Definition at line 54 of file session_handler.php.