OSDN Git Service

Add files via upload
[idb/iDB.git.git] / sql.php
diff --git a/sql.php b/sql.php
index 812f1fa..3d53885 100644 (file)
--- a/sql.php
+++ b/sql.php
@@ -8,10 +8,10 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     Revised BSD License for more details.
 
-    Copyright 2004-2014 iDB Support - http://idb.berlios.de/
-    Copyright 2004-2014 Game Maker 2k - http://gamemaker2k.org/
+    Copyright 2004-2019 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
+    Copyright 2004-2019 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
 
-    $FileInfo: sql.php - Last Update: 07/10/2014 SVN 788 - Author: cooldude2k $
+    $FileInfo: sql.php - Last Update: 08/02/2019 SVN 905 - Author: cooldude2k $
 */
 /* Some ini setting changes uncomment if you need them. 
    Display PHP Errors */
@@ -34,7 +34,6 @@ if(!defined("E_DEPRECATED")) { define("E_DEPRECATED", 0); }
 @error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
 /* Get rid of session id in urls */
 if(!in_array("ini_set", $disfunc)) {
-@ini_set("date.timezone","UTC"); 
 @ini_set("default_mimetype","text/html"); 
 @ini_set("zlib.output_compression", false);
 @ini_set("zlib.output_compression_level", -1);
@@ -70,6 +69,43 @@ ini_set("arg_separator.input",$Settings['qstr']); } }
 if(!isset($Settings['idburl'])) { $Settings['idburl'] = null; }
 if(isset($Settings['BoardUUID'])) { $Settings['BoardUUID'] = base64_decode($Settings['BoardUUID']); 
 header("Board-Unique-ID: ".$Settings['BoardUUID']); }
+function unparse_url($parsed_url) {
+  $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
+  $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
+  $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
+  $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
+  $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
+  $pass     = ($user || $pass) ? "$pass@" : '';
+  $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
+  $query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
+  $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
+  return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
+} 
+$OrgBoardURL = $Settings['idburl'];
+$PreBestURL = parse_url($Settings['idburl']);
+$PreServURL = parse_url((isset($_SERVER['HTTPS']) ? "https" : "http") . "://".$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1));
+if($PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
+   $PreBestURL['host'] = "localhost";
+   $PreBestURL['path'] = $PreServURL['path'];
+   $Settings['idburl'] = unparse_url($PreBestURL); }
+if($PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])!="localpath") {
+   $PreBestURL['host'] = $PreServURL['host'];
+   $Settings['idburl'] = unparse_url($PreBestURL); }
+if($PreBestURL['host']!="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
+   $PreBestURL['path'] = $PreServURL['path'];
+   $Settings['idburl'] = unparse_url($PreBestURL); }
+$OrgWebSiteURL = $Settings['weburl'];
+$PreWestURL = parse_url($Settings['weburl']);
+if($PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
+   $PreWestURL['host'] = $PreServURL['host'];
+   $PreWestURL['path'] = $PreServURL['path'];
+   $Settings['weburl'] = unparse_url($PreWestURL); }
+if($PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])!="localpath") {
+   $PreWestURL['host'] = $PreServURL['host'];
+   $Settings['weburl'] = unparse_url($PreWestURL); }
+if($PreWestURL['host']!="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
+   $PreWestURL['path'] = $PreServURL['path'];
+   $Settings['weburl'] = unparse_url($PreWestURL); }
 if(!isset($Settings['fixbasedir'])) { $Settings['fixbasedir'] = null; }
 if(!isset($Settings['fixpathinfo'])) { $Settings['fixpathinfo'] = null; }
 if(!isset($Settings['fixcookiedir'])) { $Settings['fixcookiedir'] = null; }
@@ -80,7 +116,7 @@ if(!isset($Settings['showverinfo'])) {
        $Settings['showverinfo'] = "on"; }
 if(!isset($Settings['sqldb'])) {
 header("Content-Type: text/plain; charset=UTF-8");
-header('Location: install.php'); }
+header('Location: install.php?act=Part1'); }
 if(!isset($Settings['fixpathinfo'])) {
        $Settings['fixpathinfo'] = "off"; }
 if($Settings['fixpathinfo']=="off") {
@@ -134,12 +170,23 @@ if(!in_array("ini_set", $disfunc)) {
 @ini_set('default_charset', $Settings['charset']); }
 //session_save_path($SettDir['inc']."temp/");
 if(!isset($Settings['sqldb'])) { 
-if(file_exists("install.php")) { header('Location: install.php'); die(); } 
+if(file_exists("install.php")) { header('Location: install.php?act=Part1'); die(); } 
 if(!file_exists("install.php")) { header("Content-Type: text/plain; charset=UTF-8");
 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again."; die(); } }
-if(isset($Settings['sqldb'])&&
-       function_exists("date_default_timezone_set")) { 
-       @date_default_timezone_set("UTC"); }
+if(isset($Settings['sqldb'])) { 
+       $deftz = new DateTimeZone(date_default_timezone_get());
+       $defcurtime = new DateTime();
+       $defcurtime->setTimezone($deftz);
+       $utctz = new DateTimeZone("UTC");
+       $utccurtime = new DateTime();
+       $utccurtime->setTimestamp($defcurtime->getTimestamp());
+       $utccurtime->setTimezone($utctz);
+       $servtz = new DateTimeZone($Settings['DefaultTimeZone']);
+       $servcurtime = new DateTime();
+       $servcurtime->setTimestamp($defcurtime->getTimestamp());
+       $servcurtime->setTimezone($servtz);
+       $usercurtime = new DateTime();
+       $usercurtime->setTimestamp($defcurtime->getTimestamp()); }
 if(!isset($Settings['sqlhost'])) { $Settings['sqlhost'] = "localhost"; }
 if($Settings['fixpathinfo']=="on") {
        $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
@@ -183,10 +230,11 @@ if(!isset($Settings['use_hashtype'])) {
        $Settings['use_hashtype'] = "sha1"; }
 if(!function_exists('hash')||!function_exists('hash_algos')) {
 if($Settings['use_hashtype']!="md5"&&
-   $Settings['use_hashtype']!="sha1") {
+   $Settings['use_hashtype']!="sha1"&&
+   $Settings['use_hashtype']!="bcrypt") {
        $Settings['use_hashtype'] = "sha1"; } }
-if(function_exists('hash')&&function_exists('hash_algos')) {
-if(!in_array($Settings['use_hashtype'],hash_algos())) {
+if((function_exists('hash')&&function_exists('hash_algos'))||function_exists('password_hash')) {
+if(!in_array($Settings['use_hashtype'],hash_algos())&&$Settings['use_hashtype']!="bcrypt") {
        $Settings['use_hashtype'] = "sha1"; }
 if($Settings['use_hashtype']!="md2"&&
    $Settings['use_hashtype']!="md4"&&
@@ -196,16 +244,15 @@ if($Settings['use_hashtype']!="md2"&&
    $Settings['use_hashtype']!="sha256"&&
    $Settings['use_hashtype']!="sha384"&&
    $Settings['use_hashtype']!="sha512"&&
+   $Settings['use_hashtype']!="sha3-224"&&
+   $Settings['use_hashtype']!="sha3-256"&&
+   $Settings['use_hashtype']!="sha3-384"&&
+   $Settings['use_hashtype']!="sha3-512"&&
    $Settings['use_hashtype']!="ripemd128"&&
    $Settings['use_hashtype']!="ripemd160"&&
    $Settings['use_hashtype']!="ripemd256"&&
    $Settings['use_hashtype']!="ripemd320"&&
-   $Settings['use_hashtype']!="salsa10"&&
-   $Settings['use_hashtype']!="salsa20"&&
-   $Settings['use_hashtype']!="snefru"&&
-   $Settings['use_hashtype']!="snefru256"&&
-   $Settings['use_hashtype']!="gost"&&
-   $Settings['use_hashtype']!="joaat") {
+   $Settings['use_hashtype']!="bcrypt") {
        $Settings['use_hashtype'] = "sha1"; } }
 // Check to see if variables are set
 require_once($SettDir['misc'].'setcheck.php');
@@ -283,7 +330,10 @@ if(isset($Settings['sql_collate'])&&!isset($Settings['sql_charset'])) {
                $Settings['sql_charset'] = "latin1"; }
        if($Settings['sql_collate']=="utf8_bin"||
                $Settings['sql_collate']=="utf8_general_ci"||
-               $Settings['sql_collate']=="utf8_unicode_ci") {
+               $Settings['sql_collate']=="utf8_unicode_ci"||
+               $Settings['sql_collate']=="utf8mb4_bin"||
+               $Settings['sql_collate']=="utf8mb4_general_ci"||
+               $Settings['sql_collate']=="utf8mb4_unicode_ci") {
                $Settings['sql_charset'] = "utf8"; } }
 if(isset($Settings['sql_collate'])&&isset($Settings['sql_charset'])) {
        if($Settings['sql_charset']=="ascii") {
@@ -295,11 +345,22 @@ if(isset($Settings['sql_collate'])&&isset($Settings['sql_charset'])) {
                $Settings['sql_collate']!="latin1_general_ci"&&
                $Settings['sql_collate']!="latin1_general_cs") {
                $Settings['sql_collate'] = "latin1_general_ci"; } }
-       if($Settings['sql_charset']=="utf8") {
+       if($Settings['sql_charset']=="utf8" || $Settings['sql_charset']=="utf8mb4") {
        if($Settings['sql_collate']!="utf8_bin"&&
                $Settings['sql_collate']!="utf8_general_ci"&&
-               $Settings['sql_collate']!="utf8_unicode_ci") {
-               $Settings['sql_collate'] = "utf8_unicode_ci"; } }
+               $Settings['sql_collate']!="utf8_unicode_ci"&&
+               $Settings['sql_collate']!="utf8mb4_bin"&&
+               $Settings['sql_collate']!="utf8mb4_general_ci"&&
+               $Settings['sql_collate']!="utf8mb4_unicode_ci") {
+               $Settings['sql_collate'] = "utf8mb4_unicode_ci"; } }
+       if($Settings['sql_collate']=="utf8_bin"||
+               $Settings['sql_collate']=="utf8_general_ci"||
+               $Settings['sql_collate']=="utf8_unicode_ci") {
+               $Settings['sql_charset'] = "utf8"; }
+       if($Settings['sql_collate']=="utf8mb4_bin"||
+               $Settings['sql_collate']=="utf8mb4_general_ci"||
+               $Settings['sql_collate']=="utf8mb4_unicode_ci") {
+               $Settings['sql_charset'] = "utf8mb4"; }
        $SQLCollate = $Settings['sql_collate'];
        $SQLCharset = $Settings['sql_charset']; }
 if(!isset($Settings['sql_collate'])||!isset($Settings['sql_charset'])) {
@@ -312,8 +373,8 @@ if($Settings['charset']=="ISO-8859-15") {
        $SQLCollate = "latin1_general_ci";
        $SQLCharset = "latin1"; }
 if($Settings['charset']=="UTF-8") {
-       $SQLCollate = "utf8_unicode_ci";
-       $SQLCharset = "utf8"; } 
+       $SQLCollate = "utf8mb4_unicode_ci";
+       $SQLCharset = "utf8mb4"; } 
 $Settings['sql_collate'] = $SQLCollate;
 $Settings['sql_charset'] = $SQLCharset; }
 sql_set_charset($SQLCharset,$SQLStat);
@@ -336,7 +397,7 @@ if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
 $MkIndexFile = $exfile['index'].$Settings['file_ext']; }
 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
 $MkIndexFile = $exfile['index']; }
-$temp_session_data = "ViewingPage|s:9:\"?act=view\";ViewingFile|s:".strlen($MkIndexFile).":\"".$MkIndexFile."\";PreViewingTitle|s:7:\"Viewing\";ViewingTitle|s:11:\"Board index\";UserID|s:1:\"0\";UserIP|s:".strlen($_SERVER['REMOTE_ADDR']).":\"".$_SERVER['REMOTE_ADDR']."\";UserGroup|s:".strlen($Settings['GuestGroup']).":\"".$Settings['GuestGroup']."\";UserGroupID|s:1:\"4\";UserTimeZone|s:".strlen($Settings['DefaultTimeZone']).":\"".$Settings['DefaultTimeZone']."\";UserDST|s:".strlen($Settings['DefaultDST']).":\"".$Settings['DefaultDST']."\";";
+$temp_session_data = "ViewingPage|s:9:\"?act=view\";ViewingFile|s:".strlen($MkIndexFile).":\"".$MkIndexFile."\";PreViewingTitle|s:7:\"Viewing\";ViewingTitle|s:11:\"Board index\";UserID|s:1:\"0\";UserIP|s:".strlen($_SERVER['REMOTE_ADDR']).":\"".$_SERVER['REMOTE_ADDR']."\";UserGroup|s:".strlen($Settings['GuestGroup']).":\"".$Settings['GuestGroup']."\";UserGroupID|s:1:\"4\";UserTimeZone|s:".strlen($Settings['DefaultTimeZone']).":\"".$Settings['DefaultTimeZone']."\";";
 $alt_temp_session_data['ViewingPage'] = "?act=view";
 $alt_temp_session_data['ViewingFile'] = $MkIndexFile;
 $alt_temp_session_data['PreViewingTitle'] = "Viewing";
@@ -345,7 +406,6 @@ $alt_temp_session_data['UserID'] = "0";
 $alt_temp_session_data['UserIP'] = $_SERVER['REMOTE_ADDR'];
 $alt_temp_session_data['UserGroupID'] = "4";
 $alt_temp_session_data['UserTimeZone'] = $Settings['DefaultTimeZone'];
-$alt_temp_session_data['UserDST'] = $Settings['DefaultDST'];
 $alttemp_session_data = serialize($alt_temp_session_data);
 $alt_temp_session_data = $alttemp_session_data;
 $alttemp_session_data = null;
@@ -368,12 +428,18 @@ global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent,$temp_session
 $result = sql_query(sql_pre_query("SELECT * FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id)),$SQLStat);
 if (!sql_num_rows($result)) {
 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\"<>'%s' AND \"ip_address\"='%s' AND \"user_agent\"='%s'", array($id,$temp_user_ip,$temp_user_agent)),$SQLStat);
-$time = GMTimeStamp();
+$utctz = new DateTimeZone("UTC");
+$utccurtime = new DateTime();
+$utccurtime->setTimezone($utctz);
+$time = $utccurtime->getTimestamp();
 sql_query(sql_pre_query("INSERT INTO \"".$sqltable."sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"ip_address\", \"expires\") VALUES\n".
 "('%s', '%s', '%s', '%s', '%s', %i)", array($id,$temp_session_data,$alt_temp_session_data,$temp_user_agent,$temp_user_ip,$time)),$SQLStat);
 return '';
 } else {
-$time = GMTimeStamp();
+$utctz = new DateTimeZone("UTC");
+$utccurtime = new DateTime();
+$utccurtime->setTimezone($utctz);
+$time = $utccurtime->getTimestamp();
 $predata = sql_num_rows($result);
 $data = "";
 if($predata > 0) {
@@ -384,7 +450,10 @@ return $data; } }
 //Session Write Function
 function sql_session_write($id,$data) {
 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent;
-$time = GMTimeStamp();
+$utctz = new DateTimeZone("UTC");
+$utccurtime = new DateTime();
+$utccurtime->setTimezone($utctz);
+$time = $utccurtime->getTimestamp();
 $rs = sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"serialized_data\"='%s',\"user_agent\"='%s',\"ip_address\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,serialize($_SESSION),$temp_user_agent,$temp_user_ip,$time,$id)),$SQLStat);
 return true; }
 //Session Destroy Function
@@ -395,7 +464,10 @@ return true; }
 //Session Garbage Collection Function
 function sql_session_gc($maxlifetime) {
 global $sqltable,$SQLStat;
-$time = GMTimeStamp() - $maxlifetime;
+$utctz = new DateTimeZone("UTC");
+$utccurtime = new DateTime();
+$utccurtime->setTimezone($utctz);
+$time = $utccurtime->getTimestamp() - $maxlifetime;
 //sql_query(sql_pre_query('DELETE FROM \"'.$sqltable.'sessions\" WHERE \"expires\" < UNIX_TIMESTAMP();', array(null)),$SQLStat);
 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"expires\" < %i", array($time)),$SQLStat);
 return true; }
@@ -416,13 +488,24 @@ header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
 if(!isset($_COOKIE[$Settings['sqltable']."sess"])) {
-$exptime = GMTimeStamp() - ini_get("session.gc_maxlifetime");
+$exptime = $utccurtime->getTimestamp() - ini_get("session.gc_maxlifetime");
 sql_query(sql_pre_query("DELETE FROM \"".$Settings['sqltable']."sessions\" WHERE \"expires\" < %i OR \"ip_address\"='%s' AND \"user_agent\"='%s'", array($exptime,$temp_user_ip,$temp_user_agent)),$SQLStat); }
 if(!isset($_SESSION['CheckCookie'])) {
 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
 session_name($Settings['sqltable']."sess");
-session_start();
+if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
+session_start([
+    'use_trans_sid' => false,
+    'use_cookies' => true,
+    'use_only_cookies' => true,
+    'gc_probability' => 1,
+    'gc_divisor' => 100,
+    'gc_maxlifetime' => 1440,
+    'hash_function' => 1,
+    'hash_bits_per_character' => 6,
+    'name' => $Settings['sqltable']."sess",
+]); }
 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
 $iDBSessCloseDB = false;
 $_SESSION['ShowActHidden'] = "no";
@@ -431,7 +514,18 @@ require($SettDir['inc'].'prelogin.php');
 session_write_close(); } }
 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
 session_name($Settings['sqltable']."sess");
-session_start();
+if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
+session_start([
+    'use_trans_sid' => false,
+    'use_cookies' => true,
+    'use_only_cookies' => true,
+    'gc_probability' => 1,
+    'gc_divisor' => 100,
+    'gc_maxlifetime' => 1440,
+    'hash_function' => 1,
+    'hash_bits_per_character' => 6,
+    'name' => $Settings['sqltable']."sess",
+]); }
 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
 $iDBSessCloseDB = true;
 output_reset_rewrite_vars();
@@ -460,7 +554,11 @@ $iopts = array(
                 "From: ".$isiteurl."\r\n".
                 "Via: ".$_SERVER['REMOTE_ADDR']."\r\n".
                 "Forwarded: ".$_SERVER['REMOTE_ADDR']."\r\n".
+                "X-Real-IP: ".$_SERVER['REMOTE_ADDR']."\r\n".
                 "X-Forwarded-For: ".$_SERVER['REMOTE_ADDR']."\r\n".
+                "X-Forwarded-Host: ".$URLsTest['host']."\r\n".
+                "X-Forwarded-Proto: ".$URLsTest['scheme']."\r\n".
+                "Board-Unique-ID: ".$Settings['BoardUUID']."\r\n".
                 "Client-IP: ".$_SERVER['REMOTE_ADDR']."\r\n"
   )
 );
@@ -566,7 +664,8 @@ if($Settings['use_captcha']=="on") {
 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
        if($Settings['captcha_clean']=="on") { ob_clean(); }
        require($SettDir['inc']."captcha.php");
-       $aFonts = array('inc/fonts/VeraBd.ttf', 'inc/fonts/VeraBI.ttf', 'inc/fonts/VeraIt.ttf', 'inc/fonts/Vera.ttf');
+       $aFontDir = dirname(__FILE__)."/inc/fonts/";
+       $aFonts = array($aFontDir.'VeraBd.ttf', $aFontDir.'VeraBI.ttf', $aFontDir.'VeraIt.ttf', $aFontDir.'Vera.ttf');
        $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
        $RNumSize = rand(7,17); $i=0; $RandNum = null;
        while ($i <= $RNumSize) {
@@ -599,22 +698,10 @@ if(!isset($_SESSION['UserTimeZone'])) {
        if(isset($Settings['DefaultTimeZone'])) { 
        $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
        if(!isset($Settings['DefaultTimeZone'])) { 
-       $_SESSION['UserTimeZone'] = SeverOffSet().":00"; } } }
-$checktime = explode(":",$_SESSION['UserTimeZone']);
-if(count($checktime)!=2) {
-       if(!isset($checktime[0])) { $checktime[0] = "0"; }
-       if(!isset($checktime[1])) { $checktime[1] = "00"; }
-       $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
-if(!is_numeric($checktime[0])) { $checktime[0] = "0"; }
-if(!is_numeric($checktime[1])) { $checktime[1] = "00"; }
-if($checktime[1]<0) { $checktime[1] = "00"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
-$checktimea = array("offset" => $_SESSION['UserTimeZone'], "hour" => $checktime[0], "minute" => $checktime[1]);
-if(!isset($_SESSION['UserDST'])) { $_SESSION['UserDST'] = null; }
-if($_SESSION['UserDST']==null) {
-if($Settings['DefaultDST']=="off") { 
-       $_SESSION['UserDST'] = "off"; }
-if($Settings['DefaultDST']=="on") { 
-       $_SESSION['UserDST'] = "on"; } }
+       $_SESSION['UserTimeZone'] = date_default_timezone_get(); } } }
+$usertz = new DateTimeZone($_SESSION['UserTimeZone']);
+$usercurtime->setTimestamp($defcurtime->getTimestamp());
+$usercurtime->setTimezone($usertz);
 // Guest Stuff
 if(isset($_SESSION['MemberName'])||
    isset($_COOKIE['MemberName'])) {
@@ -656,7 +743,7 @@ if($_GET['theme']=="../"||$_GET['theme']=="./") {
 $_GET['theme']=$Settings['DefaultTheme']; $_SESSION['Theme']=$Settings['DefaultTheme']; }
 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
-$NewDay=GMTimeStamp();
+$NewDay=$utccurtime->getTimestamp();
 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
 sql_query($qnewskin,$SQLStat); }
 /* The file Theme Exists */ }
@@ -669,7 +756,7 @@ $OldTheme = $_SESSION['Theme'];
 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
 if($OldTheme!=$_SESSION['Theme']) { 
-$NewDay=GMTimeStamp();
+$NewDay=$utccurtime->getTimestamp();
 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
 sql_query($qnewskin,$SQLStat); } }
 $_GET['theme']=$_SESSION['Theme']; }
@@ -694,7 +781,7 @@ if($themenum<=0) {
 $_GET['theme'] = $Settings['DefaultTheme']; 
 $_SESSION['Theme'] = $Settings['DefaultTheme']; 
 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
-$NewDay=GMTimeStamp();
+$NewDay=$utccurtime->getTimestamp();
 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
 sql_query($qnewskin,$SQLStat); }
 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
@@ -705,7 +792,7 @@ if($_GET['theme']==null) {
 if($_SESSION['Theme']!=null) {
 $_GET['theme'] = $_SESSION['Theme']; } }
 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
-$NewDay=GMTimeStamp();
+$NewDay=$utccurtime->getTimestamp();
 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
 sql_query($qnewskin,$SQLStat); } } 
 require($SettDir['inc'].'sqlthemes.php');