44 include_once (
'Class.QueryDb.php');
45 include_once (
'Class.DbObj.php');
46 include_once (
'Class.Log.php');
47 include_once (
'Class.User.php');
48 include_once (
'Class.SessionConf.php');
49 include_once (
"Class.SessionCache.php");
67 var
$sqlcreate =
"create table sessions ( id varchar(100),
70 last_seen timestamp not null DEFAULT now() );
71 create unique index sessions_idx on sessions(id);
72 create index sessions_idx_name on sessions(name);
73 create index sessions_idx_userid on sessions(userid);";
82 parent::__construct();
84 $this->last_seen = strftime(
'%d/%m/%Y %H:%M:%S %Z', time());
98 $query->addQuery(
"id = '" . pg_escape_string(
$id) .
"'");
100 $createNewSession =
true;
104 $createNewSession =
false;
106 session_name($this->session_name);
109 @session_write_close();
114 if ($createNewSession) {
116 if (
$u->SetLoginName($_SERVER[
'PHP_AUTH_USER'])) {
124 if ($_SERVER[
'HTTP_HOST'] !=
"") {
125 if (!$_SERVER[
"REDIRECT_URL"]) {
134 $turl = @parse_url(
$_SERVER[
"REQUEST_URI"]);
136 if (substr($turl[
'path'], -1) !=
'/') {
137 $path = dirname($turl[
'path']) .
'/';
139 $path = $turl[
'path'];
142 setcookie($this->name,
$id, $ttl,
$path);
144 setcookie($this->name,
$id, $ttl);
153 if ($_SERVER[
'HTTP_HOST'] !=
"") {
154 session_name($this->name);
155 session_id($this->
id);
158 @session_write_close();
160 setcookie($this->name,
false, time() - 3600);
163 $this->status = $this->SESSION_CT_CLOSE;
164 return $this->status;
171 $this->
exec_query(
"delete from sessions where name = '" . pg_escape_string($this->name) .
"'");
172 $this->status = $this->SESSION_CT_CLOSE;
173 return $this->status;
180 if (!
$uid > 0)
return;
181 $this->
exec_query(
"delete from sessions where userid= '" . pg_escape_string(
$uid) .
"'");
182 $this->status = $this->SESSION_CT_CLOSE;
183 return $this->status;
188 $idsess = $this->
newId();
190 if ($_SERVER[
'HTTP_HOST'] !=
"") {
191 session_name($this->session_name);
194 @session_write_close();
200 $this->userid =
$uid;
201 $this->last_seen = strftime(
'%d/%m/%Y %H:%M:%S %Z', time());
203 $this->log->debug(
"Nouvelle Session : {$this->id}");
213 $this->status = $this->SESSION_CT_ARGS;
214 return $this->status;
219 if ($_SERVER[
'HTTP_HOST'] !=
"") {
221 session_name($this->name);
222 session_id($this->
id);
225 @session_write_close();
238 session_name($this->name);
239 session_id($this->
id);
241 if (isset($_SESSION[$k])) {
242 $val = $_SESSION[$k];
243 @session_write_close();
246 @session_write_close();
259 if ($_SERVER[
'HTTP_HOST'] !=
"") {
260 session_name($this->name);
261 session_id($this->
id);
263 unset($_SESSION[$k]);
264 @session_write_close();
274 $this->log->debug(
"newId");
275 $magic =
new SessionConf($this->dbaccess,
"MAGIC");
278 return md5(uniqid($m));
286 return (time() + $ttliv);
293 if ($ttlParamName ==
'') {
295 $ttlParamName =
'CORE_GUEST_SESSIONTTL';
297 $ttlParamName =
'CORE_SESSIONTTL';
300 return getParam($ttlParamName, $default);
305 return getParam(
"CORE_SESSIONGCPROBABILITY", $default);
310 $this->last_seen = strftime(
'%d/%m/%Y %H:%M:%S %Z', time());
319 return $this->
exec_query(sprintf(
"DELETE FROM sessions WHERE userid != %s AND last_seen < timestamp 'now()' - interval '%s seconds'",
ANONYMOUS_ID, pg_escape_string($ttl)));
328 return $this->
exec_query(sprintf(
"DELETE FROM sessions WHERE userid = %s AND last_seen < timestamp 'now()' - interval '%s seconds'",
ANONYMOUS_ID, pg_escape_string($ttl)));
339 $p = rand() / getrandmax();
343 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " .
"Error cleaning up user sessions: " .
$err);
347 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " .
"Error cleaning up guest sessions: " .
$err);
355 if (!is_numeric(
$uid)) {
357 if (
$u->SetLoginName(
$uid)) {
360 $err =
"Could not resolve login name '" .
$uid .
"' to uid";
361 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " .
$err);
365 $this->userid =
$uid;
371 include_once (
'WHAT/Lib.Prefix.php');
375 $sessionDir = sprintf(
"%s/session", $pubdir);
376 if (!is_dir($sessionDir)) {
377 trigger_error(sprintf(
"Session directory '%s' does not exists.", $sessionDir));
381 if (!is_writable($sessionDir)) {
382 trigger_error(sprintf(
"Session directory '%s' is not writable.", $sessionDir));
391 include_once (
'FDL/Lib.Util.php');
396 if ($now > $last_seen + $ttl) {
405 include_once (
'WHAT/Lib.Prefix.php');
407 if ($sessid === null) {
410 $sessionFile = sprintf(
"%s/session/sess_%s", $pubdir, $sessid);
411 if (file_exists($sessionFile)) {
412 unlink($sessionFile);