ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.Session.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24// Datei: class.Session.inc
25// Benoetigt: mind. 4.0.1pl2
26
33class Session {
34 var $version = 106; // V1.06
35 var $usesCookies = false; // Client nimmt Cookies an
36 var $transSID = false; // Wurde mit --enable-trans-sid
37 // kompiliert
38
39//---------------------------------------------------------
40
45 function __construct($sessionName="SESSID") {
46 $this->sendNoCacheHeader();
47
48 ini_set("session.cookie_httponly", 1);
49 if(version_compare(PHP_VERSION, '7.1.0', '>=')) {
50 ini_set("session.sid_length", "32");
51 } else {
52 // force 4 hash bits per character for session_id // Sascha Hofmann (2005-10-19)
53 ini_set("session.hash_bits_per_character", "4");
54 }
55
56 // Session-Namen setzen, Session initialisieren
57 session_name(isset($sessionName)
58 ? $sessionName
59 : session_name());
60
61 @session_start();
62
63 // Prüen ob die Session-ID die Standardlänge
64 // von 32 Zeichen hat,
65 // ansonsten Session-ID neu setzen
66 if (strlen(session_id()) < 32)
67 {
68 mt_srand ((double)microtime()*1000000);
69 session_id(md5(uniqid(mt_rand())));
70 }
71
72 // Prüfen, ob eine Session-ID übergeben wurde
73 // (über Cookie, POST oder GET)
74 $IDpassed = false;
75 if ( isset($_COOKIE[session_name()]) &&
76 @strlen($_COOKIE[session_name()]) >= 32
77 ) $IDpassed = true;
78
79 if (!$IDpassed)
80 {
81 // Es wurde keine (gültige) Session-ID übergeben.
82 // Script-Parameter der URL zufügen
83
84 $query = @$_SERVER["QUERY_STRING"] != "" ? "?".$_SERVER["QUERY_STRING"] : "";
85
86 header("Status: 302 Found");
87
88 // Script terminiert
89 $this->redirectTo($_SERVER["PHP_SELF"].$query);
90 }
91
92 // Wenn die Session-ID übergeben wurde, muss sie
93 // nicht unbedingt gültig sein!
94
95 // Für weiteren Gebrauch merken
96 $this->usesCookies =
97 (isset($_COOKIE[session_name()]) &&
98 @strlen($_COOKIE[session_name()])
99 >= 32);
100 }
101
102### -------------------------------------------------------
111 function sendNoCacheHeader() {
112 header("Expires: Sat, 05 Aug 2000 22:27:00 GMT");
113 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
114 header("Cache-Control: no-cache, must-revalidate");
115 header("Pragma: no-cache");
116 header("Cache-Control: post-check=0, pre-check=0");
117 }
118
119### -------------------------------------------------------
133 function redirectTo($pathInfo) {
134
135 // Relativer Pfad?
136 if ($pathInfo[0] != "/")
137 { $pathInfo = substr(getenv("PATH_INFO"),
138 0,
139 strrpos(getenv("PATH_INFO"),"/")+1
140 )
141 .$pathInfo;
142 }
143
144 // Läuft dieses Script auf einem non-standard Port?
145 $port = !preg_match( "/^(80|443)$/",
146 getenv("SERVER_PORT"),
147 $portMatch)
148 ? ":".getenv("SERVER_PORT")
149 : "";
150
151 // Redirect
152 header("Location: "
153 .(($portMatch[1] == 443) ? "https://" : "http://")
154 .$_SERVER["HTTP_HOST"].$port.$this->url($pathInfo));
155 exit;
156 }
157
158### -------------------------------------------------------
165 function removeTrail($pathInfo) {
166 $dummy = preg_match("/(.*)(?<!&|\?)/",$pathInfo,$match);
167 return $match[0];
168 }
169
170### -------------------------------------------------------
177 function url($pathInfo) {
178 if ($this->usesCookies || $this->transSID) return $pathInfo;
179
180 // Anchor-Fragment extrahieren
181 $dummyArray = explode("#", $pathInfo);
182 $pathInfo = $dummyArray[0];
183
184 // evtl. (kaputte) Session-ID(s) aus dem Querystring entfernen
185 $pathInfo = preg_replace( "/[?|&]".session_name()."=[^&]*/",
186 "",
187 $pathInfo);
188
189 // evtl. Query-Delimiter korrigieren
190 if (preg_match("/&/",$pathInfo) && !preg_match("/\?/",$pathInfo))
191 {
192 // 4ter Parameter für "preg_replace()" erst ab 4.0.1pl2
193 $pathInfo = preg_replace("/&/","?",$pathInfo,1);
194 }
195
196 // Restmüll entsorgen
197 $pathInfo = $this->removeTrail($pathInfo);
198
199 // Session-Name und Session-ID frisch hinzufügen
200 $pathInfo .= preg_match("/\?/",$pathInfo) ? "&" : "?";
201
202 // Anchor-Fragment wieder anfügen
203 $pathInfo .= isset($dummyArray[1]) ? "#".$dummyArray[1] : "";
204
205 return $pathInfo;
206 }
207} // of class
208
209?>
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
An exception for terminatinating execution or to throw for unit testing.
"Manueller" Session-Fallback mit PHP4
url($pathInfo)
Fallback via GET - wenn Cookies ausgeschaltet sind.
__construct($sessionName="SESSID")
Konstruktor - nimmt, wenn gewuenscht einen neuen Session-Namen entgegen.
removeTrail($pathInfo)
Entfernt mögliche abschließende "&" und "?".
redirectTo($pathInfo)
HTTP-Redirect ausführen (header("Location: ...")
sendNoCacheHeader()
Cacheing unterbinden.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']