Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 class Session {
00034 var $version = 106;
00035 var $usesCookies = false;
00036 var $transSID = false;
00037
00038
00039
00040
00045 function Session($sessionName="SESSID") {
00046 $this->sendNoCacheHeader();
00047
00048
00049 ini_set("session.hash_bits_per_character","4");
00050
00051
00052 session_name(isset($sessionName)
00053 ? $sessionName
00054 : session_name());
00055
00056 @session_start();
00057
00058
00059
00060
00061 if (strlen(session_id()) != 32)
00062 {
00063 mt_srand ((double)microtime()*1000000);
00064 session_id(md5(uniqid(mt_rand())));
00065 }
00066
00067
00068
00069 $IDpassed = false;
00070 if ( isset($_COOKIE[session_name()]) &&
00071 @strlen($_COOKIE[session_name()]) == 32
00072 ) $IDpassed = true;
00073
00074 if ( isset($_POST[session_name()]) &&
00075 @strlen($_POST[session_name()]) == 32
00076 ) $IDpassed = true;
00077
00078 if ( isset($_GET[session_name()]) &&
00079 @strlen($_GET[session_name()]) == 32
00080 ) $IDpassed = true;
00081
00082 if (!$IDpassed)
00083 {
00084
00085
00086
00087 $query = @$_SERVER["QUERY_STRING"] != "" ? "?".$_SERVER["QUERY_STRING"] : "";
00088
00089 header("Status: 302 Found");
00090
00091
00092 $this->redirectTo($_SERVER["PHP_SELF"].$query);
00093 }
00094
00095
00096
00097
00098
00099 $this->usesCookies =
00100 (isset($_COOKIE[session_name()]) &&
00101 @strlen($_COOKIE[session_name()])
00102 == 32);
00103 }
00104
00105 ### -------------------------------------------------------
00106
00114 function sendNoCacheHeader() {
00115 header("Expires: Sat, 05 Aug 2000 22:27:00 GMT");
00116 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00117 header("Cache-Control: no-cache, must-revalidate");
00118 header("Pragma: no-cache");
00119 header("Cache-Control: post-check=0, pre-check=0");
00120 }
00121
00122 ### -------------------------------------------------------
00123
00136 function redirectTo($pathInfo) {
00137
00138
00139 if ($pathInfo[0] != "/")
00140 { $pathInfo = substr(getenv("PATH_INFO"),
00141 0,
00142 strrpos(getenv("PATH_INFO"),"/")+1
00143 )
00144 .$pathInfo;
00145 }
00146
00147
00148 $port = !preg_match( "/^(80|443)$/",
00149 getenv("SERVER_PORT"),
00150 $portMatch)
00151 ? ":".getenv("SERVER_PORT")
00152 : "";
00153
00154
00155 header("Location: "
00156 .(($portMatch[1] == 443) ? "https://" : "http://")
00157 .$_SERVER["HTTP_HOST"].$port.$this->url($pathInfo));
00158 exit;
00159 }
00160
00161 ### -------------------------------------------------------
00162
00168 function removeTrail($pathInfo) {
00169 $dummy = preg_match("/(.*)(?<!&|\?)/",$pathInfo,$match);
00170 return $match[0];
00171 }
00172
00173 ### -------------------------------------------------------
00174
00180 function url($pathInfo) {
00181 if ($this->usesCookies || $this->transSID) return $pathInfo;
00182
00183
00184 $dummyArray = split("#",$pathInfo);
00185 $pathInfo = $dummyArray[0];
00186
00187
00188 $pathInfo = preg_replace( "/[?|&]".session_name()."=[^&]*/",
00189 "",
00190 $pathInfo);
00191
00192
00193 if (preg_match("/&/",$pathInfo) && !preg_match("/\?/",$pathInfo))
00194 {
00195
00196 $pathInfo = preg_replace("/&/","?",$pathInfo,1);
00197 }
00198
00199
00200 $pathInfo = $this->removeTrail($pathInfo);
00201
00202
00203 $pathInfo .= preg_match("/\?/",$pathInfo) ? "&" : "?";
00204 $pathInfo .= session_name()."=".session_id();
00205
00206
00207 $pathInfo .= isset($dummyArray[1]) ? "#".$dummyArray[1] : "";
00208
00209 return $pathInfo;
00210 }
00211
00212 ### -------------------------------------------------------
00213
00222 function hidden() {
00223 if ($this->usesCookies || $this->transSID) return "";
00224 return "<INPUT type=\"hidden\"
00225 name=\"".session_name()."\"
00226 value=\"".session_id()."\">";
00227 }
00228 }
00229
00230 ?>