Go to the documentation of this file.00001 <?php
00011 class session_php extends session_abstract {
00012
00016 protected function afterInit() {
00017 if (!session_id()) {
00018 $sessIdForce = $this->cfg->sessIdForce;
00019 if (isset($_GET[$sessIdForce]))
00020 session_id($_GET[$sessIdForce]);
00021 elseif (isset($_POST[$sessIdForce]))
00022 session_id($_POST[$sessIdForce]);
00023 session_start();
00024 if ($this->cfg->regenerateId)
00025 session_regenerate_id(true);
00026 }
00027 }
00028
00029 public function get($prm) {
00030 if ($this->check($prm)) {
00031 if (is_array($prm)) {
00032 $this->setNameSpaceInArray($prm);
00033 config::initTab($prm, array(
00034 'name'=>null,
00035 'serialize'=>false
00036 ));
00037 $name = $this->prefixNameSpace($prm['name']);
00038 $serialize = $prm['serialize'];
00039 } else {
00040 $name = $this->prefixNameSpace($prm);
00041 $serialize = false;
00042 }
00043 return $serialize? unserialize($_SESSION[$name]) : $_SESSION[$name];
00044 }
00045 return null;
00046 }
00047
00048 public function getAll() {
00049 $ret = array();
00050 $prefix = $this->prefixNameSpace('');
00051 $prefixLn = strlen($prefix);
00052 foreach($_SESSION as $k=>$v) {
00053 if (strpos($k, $prefix) === 0)
00054 $ret[substr($k, $prefixLn)] = $v;
00055 }
00056 return $ret;
00057 }
00058
00059 public function set(array $prm) {
00060 $this->setNameSpaceInArray($prm);
00061 config::initTab($prm, array(
00062 'name'=>null,
00063 'val'=>null,
00064 'serialize'=>false
00065 ));
00066 $_SESSION[$this->prefixNameSpace($prm['name'])] = $prm['serialize']? serialize($prm['val']) : $prm['val'];
00067 }
00068
00069 public function check($prm) {
00070 if (is_array($prm)) {
00071 $this->setNameSpaceInArray($prm);
00072 config::initTab($prm, array(
00073 'name'=>null,
00074 ));
00075 $name = $prm['name'];
00076 } else {
00077 $name = $prm;
00078 }
00079 return isset($_SESSION[$this->prefixNameSpace($name)]);
00080 }
00081
00090 public function del($prm, $autoPrefix=true) {
00091 if (is_array($prm)) {
00092 $this->setNameSpaceInArray($prm);
00093 $name = $prm['name'];
00094 } else {
00095 $name = $prm;
00096 }
00097 if ($autoPrefix)
00098 $name = $this->prefixNameSpace($name);
00099 unset($_SESSION[$name]);
00100 }
00101
00102 public function clear($nameSpace=true) {
00103 $tmp = array_keys($_SESSION);
00104
00105 if ($nameSpace === true)
00106 $nameSpace = $this->getNameSpace();
00107
00108 if (is_string($nameSpace)) {
00109 $this->setNameSpace($nameSpace);
00110 $tmp = array_filter($tmp, create_function('$v', 'return (strpos($v, "'.$this->prefixNameSpace('').'") === 0);'));
00111 }
00112
00113 foreach($tmp as $v)
00114 $this->del($v, false);
00115 }
00116
00122 public function getSessIdForce() {
00123 return $this->cfg->sessIdForce;
00124 }
00125
00129 private function prefixNameSpace($name) {
00130 $nameSpace = $this->cfg->nameSpace? $this->cfg->nameSpace.'_' : null;
00131 return $this->cfg->prefix.$nameSpace.$name;
00132 }
00133
00134 }