ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Session Class Reference

"Manueller" Session-Fallback mit PHP4 More...

+ Collaboration diagram for Session:

Public Member Functions

 __construct ($sessionName="SESSID")
 Konstruktor - nimmt, wenn gewuenscht einen neuen Session-Namen entgegen. More...
 
 sendNoCacheHeader ()
 Cacheing unterbinden. More...
 
 redirectTo ($pathInfo)
 HTTP-Redirect ausführen (header("Location: ...") More...
 
 removeTrail ($pathInfo)
 Entfernt mögliche abschließende "&" und "?". More...
 
 url ($pathInfo)
 Fallback via GET - wenn Cookies ausgeschaltet sind. More...
 

Data Fields

 $version = 106
 
 $usesCookies = false
 
 $transSID = false
 

Detailed Description

"Manueller" Session-Fallback mit PHP4

Author
Daniel T. Gorski danie.nosp@m.l.go.nosp@m.rski@.nosp@m.blue.nosp@m.mars..nosp@m.de

Definition at line 33 of file class.Session.php.

Constructor & Destructor Documentation

◆ __construct()

Session::__construct (   $sessionName = "SESSID")

Konstruktor - nimmt, wenn gewuenscht einen neuen Session-Namen entgegen.

Definition at line 46 of file class.Session.php.

47 {
48 $this->sendNoCacheHeader();
49
50 ini_set("session.cookie_httponly", 1);
51 if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
52 ini_set("session.sid_length", "32");
53 } else {
54 // force 4 hash bits per character for session_id // Sascha Hofmann (2005-10-19)
55 ini_set("session.hash_bits_per_character", "4");
56 }
57
58 // Session-Namen setzen, Session initialisieren
59 session_name(isset($sessionName)
60 ? $sessionName
61 : session_name());
62
63 @session_start();
64
65 // Prüen ob die Session-ID die Standardlänge
66 // von 32 Zeichen hat,
67 // ansonsten Session-ID neu setzen
68 if (strlen(session_id()) < 32) {
69 mt_srand((double) microtime()*1000000);
70 session_id(md5(uniqid(mt_rand())));
71 }
72
73 // Prüfen, ob eine Session-ID übergeben wurde
74 // (über Cookie, POST oder GET)
75 $IDpassed = false;
76 if (isset($_COOKIE[session_name()]) &&
77 @strlen($_COOKIE[session_name()]) >= 32
78 ) {
79 $IDpassed = true;
80 }
81
82 if (!$IDpassed) {
83 // Es wurde keine (gültige) Session-ID übergeben.
84 // Script-Parameter der URL zufügen
85
86 $query = @$_SERVER["QUERY_STRING"] != "" ? "?" . $_SERVER["QUERY_STRING"] : "";
87
88 header("Status: 302 Found");
89
90 // Script terminiert
91 $this->redirectTo($_SERVER["PHP_SELF"] . $query);
92 }
93
94 // Wenn die Session-ID übergeben wurde, muss sie
95 // nicht unbedingt gültig sein!
96
97 // Für weiteren Gebrauch merken
98 $this->usesCookies =
99 (isset($_COOKIE[session_name()]) &&
100 @strlen($_COOKIE[session_name()])
101 >= 32);
102 }
$_COOKIE['client_id']
Definition: server.php:9
redirectTo($pathInfo)
HTTP-Redirect ausführen (header("Location: ...")
sendNoCacheHeader()
Cacheing unterbinden.
$query
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_COOKIE, $_SERVER, $query, redirectTo(), and sendNoCacheHeader().

+ Here is the call graph for this function:

Member Function Documentation

◆ redirectTo()

Session::redirectTo (   $pathInfo)

HTTP-Redirect ausführen (header("Location: ...")

Diese Methode berücksichtigt auch nicht-standard Ports und SSL. Ein GET-Parameter beim wird bei Bedarf (Session-ID-Fallback) an die URI drangehängt. Nach dem Aufruf dieser Methode wird das aktive Script beendet und die Kontrolle wird an das Ziel-Script übergeben.

Parameters
stringZiel-Datei (z.B. "index.php")
Returns
void

Definition at line 136 of file class.Session.php.

137 {
138
139 // Relativer Pfad?
140 if ($pathInfo[0] != "/") {
141 $pathInfo = substr(
142 getenv("PATH_INFO"),
143 0,
144 strrpos(getenv("PATH_INFO"), "/")+1
145 )
146 . $pathInfo;
147 }
148
149 // Läuft dieses Script auf einem non-standard Port?
150 $port = !preg_match(
151 "/^(80|443)$/",
152 getenv("SERVER_PORT"),
153 $portMatch
154 )
155 ? ":" . getenv("SERVER_PORT")
156 : "";
157
158 // Redirect
159 header("Location: "
160 . (($portMatch[1] == 443) ? "https://" : "http://")
161 . $_SERVER["HTTP_HOST"] . $port . $this->url($pathInfo));
162 exit;
163 }
url($pathInfo)
Fallback via GET - wenn Cookies ausgeschaltet sind.

References $_SERVER, exit, and url().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeTrail()

Session::removeTrail (   $pathInfo)

Entfernt mögliche abschließende "&" und "?".

Parameters
stringString
Returns
string String ohne abschließende "&" und "?"

Definition at line 172 of file class.Session.php.

173 {
174 $dummy = preg_match("/(.*)(?<!&|\?)/", $pathInfo, $match);
175 return $match[0];
176 }

Referenced by url().

+ Here is the caller graph for this function:

◆ sendNoCacheHeader()

Session::sendNoCacheHeader ( )

Cacheing unterbinden.

Ergänze/Override "session.cache_limiter = nocache"

Parameters
void
Returns
void

Definition at line 113 of file class.Session.php.

114 {
115 header("Expires: Sat, 05 Aug 2000 22:27:00 GMT");
116 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
117 header("Cache-Control: no-cache, must-revalidate");
118 header("Pragma: no-cache");
119 header("Cache-Control: post-check=0, pre-check=0");
120 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ url()

Session::url (   $pathInfo)

Fallback via GET - wenn Cookies ausgeschaltet sind.

Parameters
stringZiel-Datei
Returns
string Ziel-Datei mit - bei Bedarf - angehängter Session-ID

Definition at line 185 of file class.Session.php.

186 {
187 if ($this->usesCookies || $this->transSID) {
188 return $pathInfo;
189 }
190
191 // Anchor-Fragment extrahieren
192 $dummyArray = explode("#", $pathInfo);
193 $pathInfo = $dummyArray[0];
194
195 // evtl. (kaputte) Session-ID(s) aus dem Querystring entfernen
196 $pathInfo = preg_replace(
197 "/[?|&]" . session_name() . "=[^&]*/",
198 "",
199 $pathInfo
200 );
201
202 // evtl. Query-Delimiter korrigieren
203 if (preg_match("/&/", $pathInfo) && !preg_match("/\?/", $pathInfo)) {
204 // 4ter Parameter für "preg_replace()" erst ab 4.0.1pl2
205 $pathInfo = preg_replace("/&/", "?", $pathInfo, 1);
206 }
207
208 // Restmüll entsorgen
209 $pathInfo = $this->removeTrail($pathInfo);
210
211 // Session-Name und Session-ID frisch hinzufügen
212 $pathInfo .= preg_match("/\?/", $pathInfo) ? "&" : "?";
213
214 // Anchor-Fragment wieder anfügen
215 $pathInfo .= isset($dummyArray[1]) ? "#" . $dummyArray[1] : "";
216
217 return $pathInfo;
218 }
removeTrail($pathInfo)
Entfernt mögliche abschließende "&" und "?".

References removeTrail().

Referenced by redirectTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $transSID

Session::$transSID = false

Definition at line 37 of file class.Session.php.

◆ $usesCookies

Session::$usesCookies = false

Definition at line 36 of file class.Session.php.

◆ $version

Session::$version = 106

Definition at line 35 of file class.Session.php.


The documentation for this class was generated from the following file: