Ticket #490: 490-jSession-start-control.diff
| File 490-jSession-start-control.diff, 12.3 kB (added by Julien, 10 months ago) |
|---|
-
lib/jelix-scripts/templates/var/config/defaultconfig.ini.php.tpl
old new 137 137 138 138 139 139 [sessions] 140 ; You can specify the way that sessions start. 141 ; - "always" means that you have nothing to do to use sessions. This is required to use PHP's $_SESSION var directly 142 ; - "ondemand" means that the session in only started when you use jSession::set(), jSession::get(), jSession::isDefined(), jSession::delete() or jSession::destroy() 143 ; - "never" means that sessions can not be started. 144 start = always 145 ; 140 146 ; You can change the session name by setting the following parameter (only accepts alpha-numeric chars) : 141 147 ; name = "mySessionName" 142 148 ; Use alternative storage engines for sessions -
lib/jelix/core/jSession.class.php
old new 20 20 class jSession { 21 21 22 22 protected static $_params; 23 protected static $_started=false; 23 24 24 25 /** 25 26 * start a session 26 27 */ 27 28 public static function start(){ 29 if($GLOBALS['gJConfig']->sessions['start'] === 'always') 30 self::_realStart(); 31 } 32 33 34 /** 35 * end a session 36 */ 37 public static function end(){ 38 if(self::$_started) 39 session_write_close(); 40 } 41 42 43 /** 44 * store some value in session 45 * @param string $name The name of the session var 46 * @param mixed $value The value of the session var 47 */ 48 public static function set($name, $value){ 49 if(!self::$_started) 50 self::_realStart(); 51 52 $name = trim($name); 53 if($name === '') 54 throw new jException('jelix~errors.jsession.invalid.varname', array($name)); 55 56 $_SESSION[$name] = $value; 57 } 58 59 60 /** 61 * read some value from session 62 * @param string $name The name of the session var 63 * @return mixed The value of the session var 64 */ 65 public static function get($name){ 66 if(!self::$_started) 67 self::_realStart(); 68 69 $name = trim($name); 70 if($name === '') 71 throw new jException('jelix~errors.jsession.invalid.varname', array($name)); 72 73 if(!isset($_SESSION[$name])) 74 return NULL; 75 76 return $_SESSION[$name]; 77 } 78 79 80 /** 81 * check if a given var is stored in the session 82 * @param string $name The name of the session var to check 83 * @return boolean 84 */ 85 public static function isDefined($name){ 86 if(!self::$_started) 87 self::_realStart(); 88 89 $name = trim($name); 90 if($name === '') 91 throw new jException('jelix~errors.jsession.invalid.varname', array($name)); 92 93 return isset($_SESSION[$name]); 94 } 95 96 97 /** 98 * unset a given var is stored in the session 99 * @param string $name The name of the session var to unset 100 */ 101 public static function delete($name){ 102 if(!self::$_started) 103 self::_realStart(); 104 105 $name = trim($name); 106 if($name === '') 107 throw new jException('jelix~errors.jsession.invalid.varname', array($name)); 108 109 unset($_SESSION[$name]); 110 } 111 112 113 /** 114 * destroys the current session 115 */ 116 public static function destroy(){ 117 if(!self::$_started) 118 self::_realStart(); 119 120 $_SESSION = array(); 121 122 if (isset($_COOKIE[session_name()])) { 123 setcookie(session_name(), '', time()-42000, '/'); 124 } 125 126 session_destroy(); 127 } 128 129 130 131 132 133 protected static function _realStart(){ 134 135 if(self::$_started) return; 136 28 137 $params = $GLOBALS['gJConfig']->sessions; 29 138 139 if($params['start'] === 'never'){ 140 throw new jException('jelix~errors.jsession.disabled'); 141 } 142 30 143 if(isset($params['storage'])){ 31 144 32 145 switch($params['storage']){ … … 61 174 } 62 175 session_name($params['name']); 63 176 } 64 177 65 178 session_start(); 66 returntrue;179 self::$_started = true; 67 180 } 68 181 69 /**70 * end a session71 */72 public static function end(){73 session_write_close();74 return true;75 }76 182 77 183 78 184 protected static function _getDao(){ … … 137 243 * dao handler for session stored in database 138 244 */ 139 245 public static function daoDestroy ($id) { 140 if (isset($_COOKIE[session_name()])) {141 setcookie(session_name(), '', time()-42000, '/');142 }143 144 246 self::_getDao()->delete($id); 145 247 return true; 146 248 } -
lib/jelix/core/defaultconfig.ini.php
old new 201 201 202 202 [sessions] 203 203 shared_session = off 204 ; You can specify the way that sessions start. 205 ; - "always" means that you have nothing to do to use sessions. This is required to use PHP's $_SESSION var directly 206 ; - "ondemand" means that the session in only started when you use jSession::set(), jSession::get(), jSession::isDefined(), jSession::delete() or jSession::destroy() 207 ; - "never" means that sessions can not be started. 208 start = always 209 ; 204 210 ; You can change the session name by setting the following parameter (only accepts alpha-numeric chars) : 205 211 ; name = "mySessionName" 206 212 ; -
lib/jelix/core-modules/jelix/locales/en_EN/errors.ISO-8859-15.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Session name cannot be empty and only accepts alpha-numeric chars. 31 jsession.disabled = (91)Support of sessions is disabled in your application's configuration (parameter start = never). 32 jsession.invalid.varname = (92)Invalid session's variable name : "%s" 31 33 32 34 #---- actions 33 35 ad.controller.file.unknow=(100)Action %s : controller file %s doesn't exists -
lib/jelix/core-modules/jelix/locales/en_EN/errors.ISO-8859-1.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Session name cannot be empty and only accepts alpha-numeric chars. 31 jsession.disabled = (91)Support of sessions is disabled in your application's configuration (parameter start = never). 32 jsession.invalid.varname = (92)Invalid session's variable name : "%s" 31 33 32 34 #---- actions 33 35 ad.controller.file.unknow=(100)Action %s : controller file %s doesn't exists -
lib/jelix/core-modules/jelix/locales/en_EN/errors.UTF-8.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Session name cannot be empty and only accepts alpha-numeric chars. 31 jsession.disabled = (91)Support of sessions is disabled in your application's configuration (parameter start = never). 32 jsession.invalid.varname = (92)Invalid session's variable name : "%s" 31 33 32 34 #---- action 33 35 ad.controller.file.unknow=(100)Action %s : controller file %s doesn't exists -
lib/jelix/core-modules/jelix/locales/en_US/errors.ISO-8859-15.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Session name cannot be empty and only accepts alpha-numeric chars. 31 jsession.disabled = (91)Support of sessions is disabled in your application's configuration (parameter start = never). 32 jsession.invalid.varname = (92)Invalid session's variable name : "%s" 31 33 32 34 #---- actions 33 35 ad.controller.file.unknow=(100)Action %s : controller file %s doesn't exists -
lib/jelix/core-modules/jelix/locales/en_US/errors.ISO-8859-1.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Session name cannot be empty and only accepts alpha-numeric chars. 31 jsession.disabled = (91)Support of sessions is disabled in your application's configuration (parameter start = never). 32 jsession.invalid.varname = (92)Invalid session's variable name : "%s" 31 33 32 34 #---- actions 33 35 ad.controller.file.unknow=(100)Action %s : controller file %s doesn't exists -
lib/jelix/core-modules/jelix/locales/en_US/errors.UTF-8.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Session name cannot be empty and only accepts alpha-numeric chars. 31 jsession.disabled = (91)Support of sessions is disabled in your application's configuration (parameter start = never). 32 jsession.invalid.varname = (92)Invalid session's variable name : "%s" 31 33 32 34 #---- action 33 35 ad.controller.file.unknow=(100)Action %s : controller file %s doesn't exists -
lib/jelix/core-modules/jelix/locales/fr_FR/errors.ISO-8859-15.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Le nom de session ne peut �e vide et ne doit contenir que des caract�s alpha-num�ques. 31 jsession.disabled = (91)Le support des sessions est d�ctiv�ans la configuration de votre application (param�e start = never). 32 jsession.invalid.varname = (92)Nom de la variable de session invalide : "%s" 31 33 32 34 #---- actions 33 35 ad.controller.file.unknow=(100)Action %s : le fichier contr�r %s n'existe pas -
lib/jelix/core-modules/jelix/locales/fr_FR/errors.ISO-8859-1.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Le nom de session ne peut �e vide et ne doit contenir que des caract�s alpha-num�ques. 31 jsession.disabled = (91)Le support des sessions est d�ctiv�ans la configuration de votre application (param�e start = never). 32 jsession.invalid.varname = (92)Nom de la variable de session invalide : "%s" 31 33 32 34 #---- actions 33 35 ad.controller.file.unknow=(100)Action %s : le fichier contr�r %s n'existe pas -
lib/jelix/core-modules/jelix/locales/fr_FR/errors.UTF-8.properties
old new 28 28 29 29 #---- jSession 30 30 jsession.name.invalid = (90)Le nom de session ne peut être vide et ne doit contenir que des caractères alpha-numériques. 31 jsession.disabled = (91)Le support des sessions est désactivé dans la configuration de votre application (paramètre start = never). 32 jsession.invalid.varname = (92)Nom de la variable de session invalide : "%s" 31 33 32 34 #---- actions 33 35 ad.controller.file.unknow=(100)Action %s : le fichier contrôleur %s n'existe pas
