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 session_name(isset($sessionName)
00050 ? $sessionName
00051 : session_name());
00052
00053 @session_start();
00054
00055
00056
00057
00058 if (strlen(session_id()) != 32)
00059 {
00060 mt_srand ((double)microtime()*1000000);
00061 session_id(md5(uniqid(mt_rand())));
00062 }
00063
00064
00065
00066 $IDpassed = false;
00067 if ( isset($_COOKIE[session_name()]) &&
00068 @strlen($_COOKIE[session_name()]) == 32
00069 ) $IDpassed = true;
00070
00071 if ( isset($_POST[session_name()]) &&
00072 @strlen($_POST[session_name()]) == 32
00073 ) $IDpassed = true;
00074
00075 if ( isset($_GET[session_name()]) &&
00076 @strlen($_GET[session_name()]) == 32
00077 ) $IDpassed = true;
00078
00079 if (!$IDpassed)
00080 {
00081
00082
00083
00084 $query = @$_SERVER["QUERY_STRING"] != "" ? "?".$_SERVER["QUERY_STRING"] : "";
00085
00086 header("Status: 302 Found");
00087
00088
00089 $this->redirectTo($_SERVER["PHP_SELF"].$query);
00090 }
00091
00092
00093
00094
00095
00096 $this->usesCookies =
00097 (isset($_COOKIE[session_name()]) &&
00098 @strlen($_COOKIE[session_name()])
00099 == 32);
00100 }
00101
00102 ### -------------------------------------------------------
00103
00111 function sendNoCacheHeader() {
00112 header("Expires: Sat, 05 Aug 2000 22:27:00 GMT");
00113 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00114 header("Cache-Control: no-cache, must-revalidate");
00115 header("Pragma: no-cache");
00116 header("Cache-Control: post-check=0, pre-check=0");
00117 }
00118
00119 ### -------------------------------------------------------
00120
00133 function redirectTo($pathInfo) {
00134
00135
00136 if ($pathInfo[0] != "/")
00137 { $pathInfo = substr(getenv("PATH_INFO"),
00138 0,
00139 strrpos(getenv("PATH_INFO"),"/")+1
00140 )
00141 .$pathInfo;
00142 }
00143
00144
00145 $port = !preg_match( "/^(80|443)$/",
00146 getenv("SERVER_PORT"),
00147 $portMatch)
00148 ? ":".getenv("SERVER_PORT")
00149 : "";
00150
00151
00152 header("Location: "
00153 .(($portMatch[1] == 443) ? "https://" : "http://")
00154 .$_SERVER["HTTP_HOST"].$port.$this->url($pathInfo));
00155 exit;
00156 }
00157
00158 ### -------------------------------------------------------
00159
00165 function removeTrail($pathInfo) {
00166 $dummy = preg_match("/(.*)(?<!&|\?)/",$pathInfo,$match);
00167 return $match[0];
00168 }
00169
00170 ### -------------------------------------------------------
00171
00177 function url($pathInfo) {
00178 if ($this->usesCookies || $this->transSID) return $pathInfo;
00179
00180
00181 $dummyArray = split("#",$pathInfo);
00182 $pathInfo = $dummyArray[0];
00183
00184
00185 $pathInfo = preg_replace( "/[?|&]".session_name()."=[^&]*/",
00186 "",
00187 $pathInfo);
00188
00189
00190 if (preg_match("/&/",$pathInfo) && !preg_match("/\?/",$pathInfo))
00191 {
00192
00193 $pathInfo = preg_replace("/&/","?",$pathInfo,1);
00194 }
00195
00196
00197 $pathInfo = $this->removeTrail($pathInfo);
00198
00199
00200 $pathInfo .= preg_match("/\?/",$pathInfo) ? "&" : "?";
00201 $pathInfo .= session_name()."=".session_id();
00202
00203
00204 $pathInfo .= isset($dummyArray[1]) ? "#".$dummyArray[1] : "";
00205
00206 return $pathInfo;
00207 }
00208
00209 ### -------------------------------------------------------
00210
00219 function hidden() {
00220 if ($this->usesCookies || $this->transSID) return "";
00221 return "<INPUT type=\"hidden\"
00222 name=\"".session_name()."\"
00223 value=\"".session_id()."\">";
00224 }
00225 }
00226
00227 ?>