3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2024 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2024 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: system.php - Last Update: 8/26/2024 SVN 1048 - Author: cooldude2k $
16 /* Some ini setting changes uncomment if you need them.
18 $disfunc = @ini_get
("disable_functions");
19 $disfunc = @preg_replace
("/[\s\t\n\r\0\x0B]+/", "", $disfunc);
20 $disfunc = $disfunc ?
explode(",", $disfunc) : [];
21 if (!in_array("ini_set", $disfunc)) {
22 @ini_set
("html_errors", false);
23 @ini_set
("track_errors", false);
24 @ini_set
("display_errors", false);
25 @ini_set
("report_memleaks", false);
26 @ini_set
("display_startup_errors", false);
27 @ini_set
("error_log", "logs/error.log");
28 @ini_set
("log_errors", "On");
29 @ini_set
("docref_ext", "");
30 @ini_set
("docref_root", "http://php.net/");
32 /* Get rid of session id in URLs */
33 @ini_set
("default_mimetype", "text/html");
34 @ini_set
("zlib.output_compression", false);
35 @ini_set
("zlib.output_compression_level", -1);
36 @ini_set
("session.use_trans_sid", false);
37 @ini_set
("session.use_cookies", true);
38 @ini_set
("session.use_only_cookies", true);
39 @ini_set
("url_rewriter.tags", "");
40 @ini_set
('zend.ze1_compatibility_mode', 0);
41 @ini_set
("ignore_user_abort", 1);
43 /* Change session garbage collection settings */
44 @ini_set
("session.gc_probability", 1);
45 @ini_set
("session.gc_divisor", 100);
46 @ini_set
("session.gc_maxlifetime", 1440);
48 /* Change session hash type */
49 @ini_set
("session.hash_function", 1);
50 @ini_set
("session.hash_bits_per_character", 6);
52 if (!defined("E_DEPRECATED")) {
53 define("E_DEPRECATED", 0);
55 @error_reporting
(E_ALL
& ~E_NOTICE
& ~E_DEPRECATED
);
57 @ignore_user_abort
(true);
58 /* Do not change anything below this line unless you know what you are doing */
59 $File3Name = basename($_SERVER['SCRIPT_NAME']);
60 if ($File3Name == "system.php" ||
$File3Name == "/system.php") {
61 header('Location: index.php');
64 if (file_exists('settings.php')) {
65 require_once('settings.php');
66 if (file_exists('extrasettings.php')) {
67 require_once('extrasettings.php');
69 if (file_exists('extendsettings.php')) {
70 require_once('extendsettings.php');
72 // Custom error handler for non-fatal errors
73 // Configuration settings
74 $errorDisplay = true; // Set to true to display errors on the screen
75 $errorLogFile = true; // Set to true to log errors to a file
76 if (!isset($SettDir['logs'])) {
77 $SettDir['logs'] = "./logs";
79 $logFilePath = $SettDir['logs'] . 'php_error_log.txt'; // Define your log file path
81 // Custom Error Handler Function
82 function customErrorHandler($errno, $errstr, $errfile, $errline)
84 global $errorDisplay, $errorLogFile, $logFilePath;
86 // List of error types we want to handle
88 E_ERROR
=> 'Fatal Error',
89 E_WARNING
=> 'Warning',
90 E_PARSE
=> 'Parse Error',
92 E_CORE_ERROR
=> 'Core Error',
93 E_CORE_WARNING
=> 'Core Warning',
94 E_COMPILE_ERROR
=> 'Compile Error',
95 E_COMPILE_WARNING
=> 'Compile Warning',
96 E_USER_ERROR
=> 'User Error',
97 E_USER_WARNING
=> 'User Warning',
98 E_USER_NOTICE
=> 'User Notice',
99 E_STRICT
=> 'Strict Notice',
100 E_RECOVERABLE_ERROR
=> 'Recoverable Error',
101 E_DEPRECATED
=> 'Deprecated Notice',
102 E_USER_DEPRECATED
=> 'User Deprecated Notice'
105 // Safely retrieve and clean the output buffer
107 if (ob_get_length()) {
108 $output = ob_get_clean(); // Get and clear the buffer without sending it
111 // Check if the error type is in our list of handled types
112 $errorType = isset($errorTypes[$errno]) ?
$errorTypes[$errno] : 'Unknown Error';
114 // Prepare the error message
115 $errorMessage = "<b>{$errorType}:</b> [$errno] $errstr - $errfile:$errline<br>";
118 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS
);
119 $backtraceMessage = getBacktraceAsString($backtrace);
121 // Display the error if enabled
124 echo "<b>Backtrace:</b><br>";
125 echo $backtraceMessage;
128 // Log the error to a file if enabled
130 logErrorToFile($logFilePath, $errorType, $errno, $errstr, $errfile, $errline, $backtrace);
133 // Output the captured content again if needed
136 // Depending on the error, you might want to stop the script
137 if ($errno === E_ERROR ||
$errno === E_PARSE ||
$errno === E_CORE_ERROR ||
$errno === E_COMPILE_ERROR
) {
141 // Return true to prevent the PHP internal error handler from executing
145 // Custom Shutdown Handler Function
146 function shutdownHandler()
148 global $errorDisplay, $errorLogFile, $logFilePath;
150 $last_error = error_get_last();
152 // Check if $last_error is not null before accessing its elements
153 if ($last_error !== null) {
154 // Check if the error type is E_ERROR or E_PARSE (fatal errors)
155 if ($last_error['type'] === E_ERROR ||
$last_error['type'] === E_PARSE ||
$last_error['type'] === E_CORE_ERROR ||
$last_error['type'] === E_COMPILE_ERROR
) {
157 // Safely retrieve and clean the output buffer
159 if (ob_get_length()) {
160 $output = ob_get_clean(); // Get and clear the buffer without sending it
163 // Prepare the error message
164 $errorMessage = "<b>Fatal Error:</b> {$last_error['message']} - {$last_error['file']}:{$last_error['line']}<br>";
167 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS
);
168 $backtraceMessage = getBacktraceAsString($backtrace);
170 // Display the error if enabled
173 echo "<b>Backtrace:</b><br>";
174 echo $backtraceMessage;
177 // Log the error to a file if enabled
179 logErrorToFile($logFilePath, 'Fatal Error', $last_error['type'], $last_error['message'], $last_error['file'], $last_error['line'], $backtrace);
182 // Output the captured content again if needed
188 // Custom Exception Handler Function
189 // Custom Exception Handler Function
190 function customExceptionHandler($exception)
192 global $errorDisplay, $errorLogFile, $logFilePath;
194 // Safely retrieve and clean the output buffer
196 if (ob_get_length()) {
197 $output = ob_get_clean(); // Get and clear the buffer without sending it
200 // Prepare the uncaught exception message
201 $errorMessage = "<b>Uncaught Exception:</b> " . $exception->getMessage() . " in " . $exception->getFile() . " on line " . $exception->getLine() . "<br>";
203 // Get the backtrace from the exception
204 $backtrace = $exception->getTrace();
205 $backtraceMessage = getBacktraceAsString($backtrace);
207 // Display the exception if enabled
210 echo "<b>Backtrace:</b><br>";
211 echo $backtraceMessage;
214 // Log the exception to a file if enabled
216 logErrorToFile($logFilePath, 'Uncaught Exception', 0, $exception->getMessage(), $exception->getFile(), $exception->getLine(), $backtrace);
219 // Output the captured content again if needed
222 // Stop the script after an uncaught exception
226 // Function to Convert Backtrace Array to String for Display/Logging
227 function getBacktraceAsString($backtrace)
229 $backtraceMessage = "";
230 foreach ($backtrace as $trace) {
231 if (isset($trace['file'])) {
232 $backtraceMessage .= "Called in <b>{$trace['file']}</b> on line <b>{$trace['line']}</b>";
233 if (isset($trace['function'])) {
234 $backtraceMessage .= " (function <b>{$trace['function']}</b>)";
236 $backtraceMessage .= "<br>";
239 return $backtraceMessage;
242 // Function to Log Errors to a File
243 function logErrorToFile($logFile, $errorType, $errno, $errstr, $errfile, $errline, $backtrace)
245 $logMessage = "[" . date('Y-m-d H:i:s') . "] {$errorType}: [{$errno}] {$errstr} in {$errfile} on line {$errline}\n";
247 // Append backtrace to the log
248 foreach ($backtrace as $trace) {
249 if (isset($trace['file'])) {
250 $logMessage .= "Called in {$trace['file']} on line {$trace['line']}";
251 if (isset($trace['function'])) {
252 $logMessage .= " (function {$trace['function']})";
258 // Append to the log file
259 file_put_contents($logFile, $logMessage, FILE_APPEND
);
262 // Set the custom error handler
263 set_error_handler("customErrorHandler");
265 // Register the shutdown function to catch fatal errors
266 register_shutdown_function('shutdownHandler');
268 // Set exception handler to catch uncaught exceptions
269 set_exception_handler('customExceptionHandler');
271 if (isset($Settings['qstr']) && isset($Settings['qstr'])) {
272 if (!in_array("ini_set", $disfunc) && $Settings['qstr'] !== "/" && $Settings['qstr'] !== "&") {
273 @ini_set
("arg_separator.output", htmlentities($Settings['qstr'], ENT_QUOTES
, $Settings['charset']));
274 @ini_set
("arg_separator.input", $Settings['qstr']);
278 if (!isset($Settings['idburl'])) {
279 $Settings['idburl'] = null;
281 if (isset($Settings['BoardUUID'])) {
282 $Settings['BoardUUID'] = base64_decode($Settings['BoardUUID']);
283 header("Board-Unique-ID: ".$Settings['BoardUUID']);
285 function unparse_url($parsed_url)
287 $scheme = isset($parsed_url['scheme']) ?
$parsed_url['scheme'] . '://' : '';
288 $host = isset($parsed_url['host']) ?
$parsed_url['host'] : '';
289 $port = isset($parsed_url['port']) ?
':' . $parsed_url['port'] : '';
290 $user = isset($parsed_url['user']) ?
$parsed_url['user'] : '';
291 $pass = isset($parsed_url['pass']) ?
':' . $parsed_url['pass'] : '';
292 $pass = ($user ||
$pass) ?
"$pass@" : '';
293 $path = isset($parsed_url['path']) ?
$parsed_url['path'] : '';
294 $query = isset($parsed_url['query']) ?
'?' . $parsed_url['query'] : '';
295 $fragment = isset($parsed_url['fragment']) ?
'#' . $parsed_url['fragment'] : '';
296 return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
298 $OrgBoardURL = $Settings['idburl'];
299 if (isset($Settings['idburl'])) {
300 $PreBestURL = parse_url($Settings['idburl']);
302 $PreServURL = parse_url((isset($_SERVER['HTTPS']) ?
"https" : "http") . "://".$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') +
1));
303 if (isset($PreBestURL['host']) && $PreBestURL['host'] == "localhost.url" && str_replace("/", "", $PreBestURL['path']) == "localpath") {
304 $PreBestURL['host'] = "localhost";
305 $PreBestURL['path'] = $PreServURL['path'];
306 $Settings['idburl'] = unparse_url($PreBestURL);
308 if (isset($PreBestURL['host']) && $PreBestURL['host'] == "localhost.url" && str_replace("/", "", $PreBestURL['path']) != "localpath") {
309 $PreBestURL['host'] = $PreServURL['host'];
310 $Settings['idburl'] = unparse_url($PreBestURL);
312 if (isset($PreBestURL['host']) && $PreBestURL['host'] != "localhost.url" && str_replace("/", "", $PreBestURL['path']) == "localpath") {
313 $PreBestURL['path'] = $PreServURL['path'];
314 $Settings['idburl'] = unparse_url($PreBestURL);
316 if (isset($Settings['weburl'])) {
317 $OrgWebSiteURL = $Settings['weburl'];
321 if (isset($Settings['idburl'])) {
322 $PreWestURL = parse_url($Settings['weburl']);
324 if (isset($PreWestURL['host']) && $PreWestURL['host'] == "localhost.url" && str_replace("/", "", $PreWestURL['path']) == "localpath") {
325 $PreWestURL['host'] = $PreServURL['host'];
326 $PreWestURL['path'] = $PreServURL['path'];
327 $Settings['weburl'] = unparse_url($PreWestURL);
329 if (isset($PreWestURL['host']) && $PreWestURL['host'] == "localhost.url" && str_replace("/", "", $PreWestURL['path']) != "localpath") {
330 $PreWestURL['host'] = $PreServURL['host'];
331 $Settings['weburl'] = unparse_url($PreWestURL);
333 if (isset($PreWestURL['host']) && $PreWestURL['host'] != "localhost.url" && str_replace("/", "", $PreWestURL['path']) == "localpath") {
334 $PreWestURL['path'] = $PreServURL['path'];
335 $Settings['weburl'] = unparse_url($PreWestURL);
337 if (!isset($Settings['fixbasedir'])) {
338 $Settings['fixbasedir'] = null;
340 if (!isset($Settings['fixpathinfo'])) {
341 $Settings['fixpathinfo'] = null;
343 if (!isset($Settings['fixcookiedir'])) {
344 $Settings['fixcookiedir'] = null;
346 if (!isset($Settings['fixredirectdir'])) {
347 $Settings['fixcookiedir'] = null;
349 if (!isset($Settings['idb_time_format'])) {
350 $Settings['idb_time_format'] = "g:i A";
352 if (!isset($Settings['idb_date_format'])) {
353 $Settings['idb_date_format'] = "F j Y";
355 if (!isset($Settings['showverinfo'])) {
356 $Settings['showverinfo'] = "on";
358 if (!isset($Settings['sqldb'])) {
359 header("Content-Type: text/plain; charset=UTF-8");
360 header('Location: install.php?act=part1');
362 if (!isset($Settings['fixpathinfo'])) {
363 $Settings['fixpathinfo'] = "off";
365 if ($Settings['fixpathinfo'] == "off") {
366 $Settings['fixpathinfo'] = null;
368 if (!isset($Settings['fixbasedir'])) {
369 $Settings['fixbasedir'] = "off";
371 if ($Settings['fixbasedir'] == "off") {
372 $Settings['fixbasedir'] = null;
374 if (!isset($Settings['fixcookiedir'])) {
375 $Settings['fixcookiedir'] = "off";
377 if ($Settings['fixcookiedir'] == "off") {
378 $Settings['fixcookiedir'] = null;
380 if (!isset($Settings['fixredirectdir'])) {
381 $Settings['fixredirectdir'] = "off";
383 if ($Settings['fixredirectdir'] == "off") {
384 $Settings['fixredirectdir'] = null;
386 $OldSettings['fixpathinfo'] = $Settings['fixpathinfo'];
387 $OldSettings['fixbasedir'] = $Settings['fixbasedir'];
388 $OldSettings['fixcookiedir'] = $Settings['fixcookiedir'];
389 $OldSettings['fixredirectdir'] = $Settings['fixredirectdir'];
390 if ($Settings['idburl'] == "localhost") {
391 header("Content-Type: text/plain; charset=UTF-8");
392 echo "500 Error: URL is malformed. Try reinstalling iDB.";
395 if ($Settings['fixbasedir'] == "on") {
396 if ($Settings['idburl'] != null && $Settings['idburl'] != "localhost") {
397 $PathsTest = parse_url($Settings['idburl']);
398 $Settings['fixbasedir'] = $PathsTest['path']."/";
399 $Settings['fixbasedir'] = str_replace("//", "/", $Settings['fixbasedir']);
402 if ($Settings['fixcookiedir'] == "on") {
403 if ($Settings['idburl'] != null && $Settings['idburl'] != "localhost") {
404 $PathsTest = parse_url($Settings['idburl']);
405 $Settings['fixcookiedir'] = $PathsTest['path']."/";
406 $Settings['fixcookiedir'] = str_replace("//", "/", $Settings['fixcookiedir']);
409 if ($Settings['fixredirectdir'] == "on") {
410 if ($Settings['idburl'] != null && $Settings['idburl'] != "localhost") {
411 $PathsTest = parse_url($Settings['idburl']);
412 $Settings['fixredirectdir'] = $PathsTest['path']."/";
413 $Settings['fixredirectdir'] = str_replace("//", "/", $Settings['fixredirectdir']);
416 if (!isset($Settings['charset'])) {
417 $Settings['charset'] = "ISO-8859-15";
419 if (isset($Settings['charset'])) {
420 if ($Settings['charset'] != "ISO-8859-15" && $Settings['charset'] != "ISO-8859-1" &&
421 $Settings['charset'] != "UTF-8" && $Settings['charset'] != "CP866" &&
422 $Settings['charset'] != "Windows-1251" && $Settings['charset'] != "Windows-1252" &&
423 $Settings['charset'] != "KOI8-R" && $Settings['charset'] != "BIG5" &&
424 $Settings['charset'] != "GB2312" && $Settings['charset'] != "BIG5-HKSCS" &&
425 $Settings['charset'] != "Shift_JIS" && $Settings['charset'] != "EUC-JP") {
426 $Settings['charset'] = "ISO-8859-15";
429 $chkcharset = $Settings['charset'];
430 if (!in_array("ini_set", $disfunc)) {
431 @ini_set
('default_charset', $Settings['charset']);
433 //session_save_path($SettDir['inc']."temp/");
434 if (!isset($Settings['sqldb'])) {
435 if (file_exists("install.php")) {
436 header('Location: install.php?act=part1');
439 if (!file_exists("install.php")) {
440 header("Content-Type: text/plain; charset=UTF-8");
441 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again.";
445 if (isset($Settings['sqldb'])) {
446 $deftz = new DateTimeZone(date_default_timezone_get());
447 $defcurtime = new DateTime();
448 $defcurtime->setTimezone($deftz);
449 $utctz = new DateTimeZone("UTC");
450 $utccurtime = new DateTime();
451 $utccurtime->setTimestamp($defcurtime->getTimestamp());
452 $utccurtime->setTimezone($utctz);
453 $servtz = new DateTimeZone($Settings['DefaultTimeZone']);
454 $servcurtime = new DateTime();
455 $servcurtime->setTimestamp($defcurtime->getTimestamp());
456 $servcurtime->setTimezone($servtz);
457 $usercurtime = new DateTime();
458 $usercurtime->setTimestamp($defcurtime->getTimestamp());
460 if (!isset($Settings['sqlhost'])) {
461 $Settings['sqlhost'] = "localhost";
463 if ($Settings['fixpathinfo'] == "on") {
464 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
465 putenv("PATH_INFO=".$_SERVER['ORIG_PATH_INFO']);
467 // Check to see if variables are set
468 if (!isset($SettDir['inc'])) {
469 $SettDir['inc'] = "inc/";
471 if (!isset($SettDir['archive'])) {
472 $SettDir['archive'] = "archive/";
474 if (!isset($SettDir['misc'])) {
475 $SettDir['misc'] = "inc/misc/";
477 if (!isset($SettDir['sql'])) {
478 $SettDir['sql'] = "inc/misc/sql/";
480 if (!isset($SettDir['admin'])) {
481 $SettDir['admin'] = "inc/admin/";
483 if (!isset($SettDir['sqldumper'])) {
484 $SettDir['sqldumper'] = "inc/admin/sqldumper/";
486 if (!isset($SettDir['mod'])) {
487 $SettDir['mod'] = "inc/mod/";
489 if (!isset($SettDir['mplayer'])) {
490 $SettDir['mplayer'] = "inc/mplayer/";
492 if (!isset($SettDir['themes'])) {
493 $SettDir['themes'] = "themes/";
495 if (!isset($SettDir['maindir']) ||
!file_exists($SettDir['maindir']) ||
!is_dir($SettDir['maindir'])) {
496 $SettDir['maindir'] = addslashes(str_replace("\\", "/", dirname(__FILE__
)."/"));
498 if (isset($SettDir['maindir'])) {
499 @chdir
($SettDir['maindir']);
501 if (!isset($Settings['use_iniset'])) {
502 $Settings['use_iniset'] = null;
504 if (!isset($Settings['clean_ob'])) {
505 $Settings['clean_ob'] = "off";
507 if (!isset($_SERVER['PATH_INFO'])) {
508 $_SERVER['PATH_INFO'] = null;
510 if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
511 $_SERVER['HTTP_ACCEPT_ENCODING'] = null;
513 if (!isset($_SERVER['HTTP_ACCEPT'])) {
514 $_SERVER['HTTP_ACCEPT'] = null;
516 if (!isset($_SERVER['HTTP_REFERER'])) {
517 $_SERVER['HTTP_REFERER'] = null;
519 if (!isset($_GET['page'])) {
520 $_GET['page'] = null;
522 if (!isset($_GET['act'])) {
525 if (!isset($_POST['act'])) {
526 $_POST['act'] = null;
528 if (!isset($_GET['modact'])) {
529 $_GET['modact'] = null;
531 if (!isset($_POST['modact'])) {
532 $_POST['modact'] = null;
534 if (!isset($_GET['id'])) {
537 if (!isset($_GET['debug'])) {
538 $_GET['debug'] = "off";
540 if (!isset($_GET['post'])) {
541 $_GET['post'] = null;
543 if (!isset($_POST['License'])) {
544 $_POST['License'] = null;
546 if (!isset($_SERVER['HTTPS'])) {
547 $_SERVER['HTTPS'] = "off";
549 if (!isset($Settings['SQLThemes'])) {
550 $Settings['SQLThemes'] = "off";
552 if ($Settings['SQLThemes'] != "on" && $Settings['SQLThemes'] != "off") {
553 $Settings['SQLThemes'] = "off";
555 require_once($SettDir['misc'].'utf8.php');
556 require_once($SettDir['inc'].'filename.php');
557 if (!isset($Settings['use_hashtype'])) {
558 $Settings['use_hashtype'] = "sha1";
560 if (!function_exists('hash') ||
!function_exists('hash_algos')) {
561 if ($Settings['use_hashtype'] != "md5" &&
562 $Settings['use_hashtype'] != "sha1" &&
563 $Settings['use_hashtype'] != "bcrypt" &&
564 $Settings['use_hashtype'] != "argon2i" &&
565 $Settings['use_hashtype'] != "argon2id") {
566 $Settings['use_hashtype'] = "sha1";
569 if ((function_exists('hash') && function_exists('hash_algos')) ||
function_exists('password_hash')) {
570 if (!in_array($Settings['use_hashtype'], hash_algos()) && $Settings['use_hashtype'] != "bcrypt") {
571 $Settings['use_hashtype'] = "sha1";
573 if ($Settings['use_hashtype'] != "md2" &&
574 $Settings['use_hashtype'] != "md4" &&
575 $Settings['use_hashtype'] != "md5" &&
576 $Settings['use_hashtype'] != "sha1" &&
577 $Settings['use_hashtype'] != "sha224" &&
578 $Settings['use_hashtype'] != "sha256" &&
579 $Settings['use_hashtype'] != "sha384" &&
580 $Settings['use_hashtype'] != "sha512" &&
581 $Settings['use_hashtype'] != "sha3-224" &&
582 $Settings['use_hashtype'] != "sha3-256" &&
583 $Settings['use_hashtype'] != "sha3-384" &&
584 $Settings['use_hashtype'] != "sha3-512" &&
585 $Settings['use_hashtype'] != "ripemd128" &&
586 $Settings['use_hashtype'] != "ripemd160" &&
587 $Settings['use_hashtype'] != "ripemd256" &&
588 $Settings['use_hashtype'] != "ripemd320" &&
589 $Settings['use_hashtype'] != "bcrypt" &&
590 $Settings['use_hashtype'] != "argon2i" &&
591 $Settings['use_hashtype'] != "argon2id") {
592 $Settings['use_hashtype'] = "sha1";
595 // Check to see if variables are set
596 require_once($SettDir['misc'].'setcheck.php');
597 $dayconv = array("year" => 29030400, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1);
598 require_once($SettDir['inc'].'function.php');
599 $Settings['bid'] = base64_encode(urlencode($Settings['idburl'].url_maker($exfile['index'], $Settings['file_ext'], "act=versioninfo", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index'], false)));
600 $Settings['ubid'] = base64_encode(urlencode($Settings['idburl'].url_maker($exfile['index'], $Settings['file_ext'], "act=versioninfo", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index'], false)));
601 if ($Settings['enable_pathinfo'] == "on") {
602 mrstring(); /* Change Path info to Get Vars :P */
604 // Check to see if variables are set
605 $qstrhtml = htmlentities($Settings['qstr'], ENT_QUOTES
, $Settings['charset']);
606 if ($Settings['enable_https'] == "on" && $_SERVER['HTTPS'] == "on") {
607 if ($Settings['idburl'] != null && $Settings['idburl'] != "localhost") {
608 $HTTPsTest = parse_url($Settings['idburl']);
609 if ($HTTPsTest['scheme'] == "http") {
610 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']);
614 $cookieDomain = null;
615 $cookieSecure = false;
616 if ($Settings['idburl'] != null && $Settings['idburl'] != "localhost") {
617 $URLsTest = parse_url($Settings['idburl']);
618 $cookieDomain = $URLsTest['host'];
619 if ($cookieDomain == "localhost") {
620 $cookieDomain = false;
622 if ($Settings['enable_https'] == "on") {
623 if ($URLsTest['scheme'] == "https") {
624 $cookieSecure = true;
626 if ($URLsTest['scheme'] != "https") {
627 $cookieSecure = false;
631 if (!in_array("ini_set", $disfunc)) {
632 @ini_set
('default_charset', $Settings['charset']);
634 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
635 $File2Name = $_SERVER['SCRIPT_NAME'];
636 /*$File3Name=str_replace($File1Name, null, $File2Name);
637 if ($File3Name=="system.php"||$File3Name=="/system.php") {
638 header('Location: index.php');
640 $File3Name = basename($_SERVER['SCRIPT_NAME']);
641 if ($File3Name == "system.php" ||
$File3Name == "/system.php") {
642 header('Location: index.php');
645 //error_reporting(E_ERROR);
646 // Check if gzip is on and if user's browser can accept gzip pages
647 if ($_GET['act'] == "MkCaptcha" ||
$_GET['act'] == "Captcha") {
648 $Settings['use_gzip'] = 'off';
650 if ($Settings['use_gzip'] == "on") {
651 if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br") && function_exists('brotli_compress')) {
652 $GZipEncode['Type'] = "brotli";
653 } elseif (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "zstd") && function_exists('zstd_compress')) {
654 $GZipEncode['Type'] = "zstd";
656 if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) {
657 $GZipEncode['Type'] = "gzip";
659 if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) {
660 $GZipEncode['Type'] = "deflate";
662 $Settings['use_gzip'] = "off";
663 $GZipEncode['Type'] = "none";
668 if ($Settings['use_gzip'] == "brotli" && function_exists('brotli_compress')) {
669 if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br")) {
670 $Settings['use_brotli'] = "on";
671 $GZipEncode['Type'] = "brotli";
673 $Settings['use_gzip'] = "off";
676 if ($Settings['use_gzip'] == "zstd" && function_exists('zstd_compress')) {
677 if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br")) {
678 $Settings['use_zstd'] = "on";
679 $GZipEncode['Type'] = "zstd";
681 $Settings['use_gzip'] = "off";
684 if ($Settings['use_gzip'] == "brotli" && !function_exists('brotli_compress')) {
685 $GZipEncode['Type'] = "gzip";
687 if ($Settings['use_gzip'] == "zstd" && !function_exists('zstd_compress')) {
688 $GZipEncode['Type'] = "gzip";
690 if ($Settings['use_gzip'] == "gzip") {
691 if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) {
692 $Settings['use_gzip'] = "on";
693 $GZipEncode['Type'] = "gzip";
695 $Settings['use_gzip'] = "off";
698 if ($Settings['use_gzip'] == "deflate") {
699 if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) {
700 $Settings['use_gzip'] = "on";
701 $GZipEncode['Type'] = "deflate";
703 $Settings['use_gzip'] = "off";
706 $iWrappers = array(null);
707 function idb_output_handler($buffer)
711 function idb_suboutput_handler($buffer)
715 if ($Settings['clean_ob'] == "on") {
716 /* Check for other output handlers/buffers are open
717 and close and get the contents in an array */
718 $numob = count(ob_list_handlers());
720 while ($iob < $numob) {
721 $old_ob_var[$iob] = ob_get_clean();
724 } ob_start("idb_output_handler");
725 if ($Settings['use_gzip'] == "on") {
726 if ($GZipEncode['Type'] != "gzip") {
727 if ($GZipEncode['Type'] != "deflate") {
728 $GZipEncode['Type'] = "gzip";
731 if ($GZipEncode['Type'] == "gzip") {
732 header("Content-Encoding: gzip");
734 if ($GZipEncode['Type'] == "deflate") {
735 header("Content-Encoding: deflate");
738 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
739 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
741 $SQLStat = sql_connect_db($Settings['sqlhost'], $Settings['sqluser'], $Settings['sqlpass'], $Settings['sqldb']);
742 if (isset($Settings['sql_collate']) && !isset($Settings['sql_charset'])) {
743 if ($Settings['sql_collate'] == "ascii_bin" ||
744 $Settings['sql_collate'] == "ascii_generel_ci") {
745 $Settings['sql_charset'] = "ascii";
747 if ($Settings['sql_collate'] == "latin1_bin" ||
748 $Settings['sql_collate'] == "latin1_general_ci" ||
749 $Settings['sql_collate'] == "latin1_general_cs") {
750 $Settings['sql_charset'] = "latin1";
752 if ($Settings['sql_collate'] == "utf8mb3_bin" ||
753 $Settings['sql_collate'] == "utf8mb3_general_ci" ||
754 $Settings['sql_collate'] == "utf8mb3_unicode_ci") {
755 $Settings['sql_charset'] = "utf8mb3";
757 if ($Settings['sql_collate'] == "utf8mb4_bin" ||
758 $Settings['sql_collate'] == "utf8mb4_general_ci" ||
759 $Settings['sql_collate'] == "utf8mb4_unicode_ci") {
760 $Settings['sql_charset'] = "utf8mb4";
763 if (isset($Settings['sql_collate']) && isset($Settings['sql_charset'])) {
764 if ($Settings['sql_charset'] == "ascii") {
765 if ($Settings['sql_collate'] != "ascii_bin" &&
766 $Settings['sql_collate'] != "ascii_generel_ci") {
767 $Settings['sql_collate'] = "ascii_generel_ci";
770 if ($Settings['sql_charset'] == "latin1") {
771 if ($Settings['sql_collate'] != "latin1_bin" &&
772 $Settings['sql_collate'] != "latin1_general_ci" &&
773 $Settings['sql_collate'] != "latin1_general_cs") {
774 $Settings['sql_collate'] = "latin1_general_ci";
777 if ($Settings['sql_charset'] == "utf8" ||
$Settings['sql_charset'] == "utf8mb4") {
778 if ($Settings['sql_collate'] != "utf8mb3_bin" &&
779 $Settings['sql_collate'] != "utf8mb3_general_ci" &&
780 $Settings['sql_collate'] != "utf8mb3_unicode_ci" &&
781 $Settings['sql_collate'] != "utf8mb4_bin" &&
782 $Settings['sql_collate'] != "utf8mb4_general_ci" &&
783 $Settings['sql_collate'] != "utf8mb4_unicode_ci") {
784 $Settings['sql_collate'] = "utf8mb4_unicode_ci";
787 if ($Settings['sql_collate'] == "utf8mb3_bin" ||
788 $Settings['sql_collate'] == "utf8mb3_general_ci" ||
789 $Settings['sql_collate'] == "utf8mb3_unicode_ci") {
790 $Settings['sql_charset'] = "utf8mb3";
792 if ($Settings['sql_collate'] == "utf8mb4_bin" ||
793 $Settings['sql_collate'] == "utf8mb4_general_ci" ||
794 $Settings['sql_collate'] == "utf8mb4_unicode_ci") {
795 $Settings['sql_charset'] = "utf8mb4";
797 $SQLCollate = $Settings['sql_collate'];
798 $SQLCharset = $Settings['sql_charset'];
800 if (!isset($Settings['sql_collate']) ||
!isset($Settings['sql_charset'])) {
801 $SQLCollate = "latin1_general_ci";
802 $SQLCharset = "latin1";
803 if ($Settings['charset'] == "ISO-8859-1") {
804 $SQLCollate = "latin1_general_ci";
805 $SQLCharset = "latin1";
807 if ($Settings['charset'] == "ISO-8859-15") {
808 $SQLCollate = "latin1_general_ci";
809 $SQLCharset = "latin1";
811 if ($Settings['charset'] == "UTF-8") {
812 $SQLCollate = "utf8mb4_unicode_ci";
813 $SQLCharset = "utf8mb4";
815 $Settings['sql_collate'] = $SQLCollate;
816 $Settings['sql_charset'] = $SQLCharset;
818 sql_set_charset($SQLCharset, $SQLStat);
819 if ($SQLStat === false) {
820 header("Content-Type: text/plain; charset=".$Settings['charset']);
821 sql_free_result($peresult);
823 echo "Sorry could not connect to sql database.\nContact the board admin about error. Error log below.";
824 echo "\n".sql_errorno($SQLStat);
826 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
827 session_write_close();
830 $sqltable = $Settings['sqltable'];
831 $temp_user_ip = $_SERVER['REMOTE_ADDR'];
832 if (!isset($_SERVER['HTTP_USER_AGENT'])) {
833 $_SERVER['HTTP_USER_AGENT'] = "";
835 // Create an array to store browser hints
836 $client_hints_json = [];
838 'user_agent' => isset($_SERVER['HTTP_SEC_CH_UA']) ?
$_SERVER['HTTP_SEC_CH_UA'] : null,
839 'is_mobile' => isset($_SERVER['HTTP_SEC_CH_UA_MOBILE']) ?
$_SERVER['HTTP_SEC_CH_UA_MOBILE'] : null,
840 'full_version' => isset($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION']) ?
$_SERVER['HTTP_SEC_CH_UA_FULL_VERSION'] : null,
841 'full_version_list' => isset($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST']) ?
$_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST'] : null,
842 'platform' => isset($_SERVER['HTTP_SEC_CH_UA_PLATFORM']) ?
$_SERVER['HTTP_SEC_CH_UA_PLATFORM'] : null,
843 'platform_version' => isset($_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION']) ?
$_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION'] : null,
844 'architecture' => isset($_SERVER['HTTP_SEC_CH_UA_ARCH']) ?
$_SERVER['HTTP_SEC_CH_UA_ARCH'] : null,
845 'bitness' => isset($_SERVER['HTTP_SEC_CH_UA_BITNESS']) ?
$_SERVER['HTTP_SEC_CH_UA_BITNESS'] : null,
846 'wow64' => isset($_SERVER['HTTP_SEC_CH_UA_WOW64']) ?
$_SERVER['HTTP_SEC_CH_UA_WOW64'] : null,
847 'model' => isset($_SERVER['HTTP_SEC_CH_UA_MODEL']) ?
$_SERVER['HTTP_SEC_CH_UA_MODEL'] : null,
848 'form_factor' => isset($_SERVER['HTTP_SEC_CH_UA_FORM_FACTOR']) ?
$_SERVER['HTTP_SEC_CH_UA_FORM_FACTOR'] : null,
849 'lang' => isset($_SERVER['HTTP_SEC_CH_LANG']) ?
$_SERVER['HTTP_SEC_CH_LANG'] : null,
850 'save_data' => isset($_SERVER['HTTP_SEC_CH_SAVE_DATA']) ?
$_SERVER['HTTP_SEC_CH_SAVE_DATA'] : null,
851 'width' => isset($_SERVER['HTTP_SEC_CH_WIDTH']) ?
$_SERVER['HTTP_SEC_CH_WIDTH'] : null,
852 'viewport_width' => isset($_SERVER['HTTP_SEC_CH_VIEWPORT_WIDTH']) ?
$_SERVER['HTTP_SEC_CH_VIEWPORT_WIDTH'] : null,
853 'viewport_height' => isset($_SERVER['HTTP_SEC_CH_VIEWPORT_HEIGHT']) ?
$_SERVER['HTTP_SEC_CH_VIEWPORT_HEIGHT'] : null,
854 'dpr' => isset($_SERVER['HTTP_SEC_CH_DPR']) ?
$_SERVER['HTTP_SEC_CH_DPR'] : null,
855 'device_memory' => isset($_SERVER['HTTP_SEC_CH_DEVICE_MEMORY']) ?
$_SERVER['HTTP_SEC_CH_DEVICE_MEMORY'] : null,
856 'rtt' => isset($_SERVER['HTTP_SEC_CH_RTT']) ?
$_SERVER['HTTP_SEC_CH_RTT'] : null,
857 'downlink' => isset($_SERVER['HTTP_SEC_CH_DOWNLINK']) ?
$_SERVER['HTTP_SEC_CH_DOWNLINK'] : null,
858 'ect' => isset($_SERVER['HTTP_SEC_CH_ECT']) ?
$_SERVER['HTTP_SEC_CH_ECT'] : null,
859 'prefers_color_scheme' => isset($_SERVER['HTTP_SEC_CH_PREFERS_COLOR_SCHEME']) ?
$_SERVER['HTTP_SEC_CH_PREFERS_COLOR_SCHEME'] : null,
860 'prefers_reduced_motion' => isset($_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_MOTION']) ?
$_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_MOTION'] : null,
861 'prefers_reduced_transparency' => isset($_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_TRANSPARENCY']) ?
$_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_TRANSPARENCY'] : null,
862 'prefers_contrast' => isset($_SERVER['HTTP_SEC_CH_PREFERS_CONTRAST']) ?
$_SERVER['HTTP_SEC_CH_PREFERS_CONTRAST'] : null,
863 'forced_colors' => isset($_SERVER['HTTP_SEC_CH_FORCED_COLORS']) ?
$_SERVER['HTTP_SEC_CH_FORCED_COLORS'] : null
865 $client_hints_json = json_encode($client_hints);
866 if ($client_hints_json == "") {
867 $client_hints_json = [];
869 if (strpos($_SERVER['HTTP_USER_AGENT'], "msie") &&
870 !strpos($_SERVER['HTTP_USER_AGENT'], "opera")) {
871 header("X-UA-Compatible: IE=Edge");
873 if (strpos($_SERVER['HTTP_USER_AGENT'], "chromeframe")) {
874 header("X-UA-Compatible: IE=Edge,chrome=1");
876 $temp_user_agent = $_SERVER['HTTP_USER_AGENT'];
877 if ($Settings['file_ext'] != "no+ext" && $Settings['file_ext'] != "no ext") {
878 $MkIndexFile = $exfile['index'].$Settings['file_ext'];
880 if ($Settings['file_ext'] == "no+ext" ||
$Settings['file_ext'] == "no ext") {
881 $MkIndexFile = $exfile['index'];
883 $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']."\";";
884 $alt_temp_session_data['ViewingPage'] = "?act=view";
885 $alt_temp_session_data['ViewingFile'] = $MkIndexFile;
886 $alt_temp_session_data['PreViewingTitle'] = "Viewing";
887 $alt_temp_session_data['ViewingTitle'] = "Board index";
888 $alt_temp_session_data['UserID'] = "0";
889 $alt_temp_session_data['UserIP'] = $_SERVER['REMOTE_ADDR'];
890 $alt_temp_session_data['UserGroupID'] = "4";
891 $alt_temp_session_data['UserTimeZone'] = $Settings['DefaultTimeZone'];
892 $alttemp_session_data = serialize($alt_temp_session_data);
893 $alt_temp_session_data = $alttemp_session_data;
894 $alttemp_session_data = null;
895 $SQLSType = $Settings['sqltype'];
896 $use_old_session = true;
897 if ($use_old_session == true) {
898 // Old Session Handling Functions
900 // Session Open Function
901 function sql_session_open($save_path, $session_name)
903 global $sess_save_path;
904 $sess_save_path = $save_path;
908 // Session Close Function
909 $iDBSessCloseDB = true;
910 function sql_session_close()
912 global $SQLStat, $iDBSessCloseDB;
913 if ($iDBSessCloseDB === true) {
914 sql_disconnect_db($SQLStat);
919 // Session Read Function
920 function sql_session_read($id)
922 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json, $temp_session_data, $alt_temp_session_data;
924 // Check if session exists
925 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
926 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
928 if ($sessionExists == 0) {
929 // Delete old sessions with the same IP and user agent
930 sql_query(sql_pre_query(
931 "DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" <> '%s' AND \"ip_address\" = '%s' AND \"user_agent\" = '%s'",
932 array($id, $temp_user_ip, $temp_user_agent)
935 // Insert new session data
936 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
937 sql_query(sql_pre_query(
938 "INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
939 array($id, $temp_session_data, $alt_temp_session_data, $temp_user_agent, $client_hints_json, $temp_user_ip, $time)
943 // Fetch the existing session data
944 $query = sql_pre_query("SELECT * FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
945 $rs = sql_query($query, $SQLStat);
946 $row = sql_fetch_assoc($rs);
948 // Free the result after fetching
949 sql_free_result($rs);
951 return $row ?
$row['session_data'] : '';
955 // Session Write Function
956 function sql_session_write($id, $data)
958 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json;
960 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
961 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
962 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
964 if ($sessionExists == 0) {
965 // Insert new session data
966 sql_query(sql_pre_query(
967 "INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
968 array($id, $data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time)
971 // Update existing session data
972 sql_query(sql_pre_query(
973 "UPDATE \"" . $sqltable . "sessions\" SET \"session_data\" = '%s', \"serialized_data\" = '%s', \"user_agent\" = '%s', \"client_hints\" = '%s', \"ip_address\" = '%s', \"expires\" = %i WHERE \"session_id\" = '%s'",
974 array($data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time, $id)
981 // Session Destroy Function
982 function sql_session_destroy($id)
984 global $sqltable, $SQLStat;
985 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id)), $SQLStat);
989 // Session Garbage Collection Function
990 function sql_session_gc($maxlifetime)
992 global $sqltable, $SQLStat;
993 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp() - $maxlifetime;
994 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"expires\" < %i", array($time)), $SQLStat);
1002 // New Session Handling Functions
1004 function sql_session_open($save_path, $session_name)
1006 global $sess_save_path;
1007 $sess_save_path = $save_path;
1011 function sql_session_close()
1014 sql_disconnect_db($SQLStat);
1018 function sql_session_read($id)
1020 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json, $temp_session_data, $alt_temp_session_data;
1022 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
1023 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
1025 if ($sessionExists == 0) {
1026 sql_query(sql_pre_query(
1027 "DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" <> '%s' AND \"ip_address\" = '%s' AND \"user_agent\" = '%s'",
1028 array($id, $temp_user_ip, $temp_user_agent)
1031 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
1032 sql_query(sql_pre_query(
1033 "INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
1034 array($id, $temp_session_data, $alt_temp_session_data, $temp_user_agent, $client_hints_json, $temp_user_ip, $time)
1038 $query = sql_pre_query("SELECT * FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
1039 $rs = sql_query($query, $SQLStat);
1040 $row = sql_fetch_assoc($rs);
1042 // Free the result after fetching
1043 sql_free_result($rs);
1045 return $row ?
$row['session_data'] : '';
1049 function sql_session_write($id, $data)
1051 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json;
1053 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
1054 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
1055 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
1057 if ($sessionExists == 0) {
1058 sql_query(sql_pre_query(
1059 "INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
1060 array($id, $data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time)
1063 sql_query(sql_pre_query(
1064 "UPDATE \"" . $sqltable . "sessions\" SET \"session_data\" = '%s', \"serialized_data\" = '%s', \"user_agent\" = '%s', \"client_hints\" = '%s', \"ip_address\" = '%s', \"expires\" = %i WHERE \"session_id\" = '%s'",
1065 array($data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time, $id)
1072 function sql_session_destroy($id)
1074 global $sqltable, $SQLStat;
1075 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id)), $SQLStat);
1079 function sql_session_gc($maxlifetime)
1081 global $sqltable, $SQLStat;
1082 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp() - $maxlifetime;
1083 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"expires\" < %i", array($time)), $SQLStat);
1088 // Register session handler functions
1089 session_set_save_handler(
1091 "sql_session_close",
1093 "sql_session_write",
1094 "sql_session_destroy",
1097 if ($cookieDomain == null) {
1098 session_set_cookie_params(0, $cbasedir);
1100 if ($cookieDomain != null) {
1101 if ($cookieSecure === true) {
1102 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1);
1104 if ($cookieSecure === false) {
1105 session_set_cookie_params(0, $cbasedir, $cookieDomain);
1108 session_cache_limiter("private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
1109 header("Cache-Control: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
1110 header("Pragma: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
1111 header("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
1112 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
1113 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
1114 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
1115 if (!isset($_COOKIE[$Settings['sqltable']."sess"])) {
1116 $exptime = $utccurtime->getTimestamp() - ini_get("session.gc_maxlifetime");
1117 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);
1119 if (!isset($_SESSION['CheckCookie'])) {
1120 if (isset($_COOKIE['SessPass']) && isset($_COOKIE['MemberName'])) {
1121 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
1122 session_name($Settings['sqltable']."sess");
1123 if (version_compare(phpversion(), '7.0', '<')) {
1127 'use_trans_sid' => false,
1128 'use_cookies' => true,
1129 'use_only_cookies' => true,
1130 'gc_probability' => 1,
1131 'gc_divisor' => 100,
1132 'gc_maxlifetime' => 1440,
1133 //'hash_function' => 1,
1134 //'hash_bits_per_character' => 6,
1135 'name' => $Settings['sqltable']."sess",
1138 if (!isset($_SESSION['UserFormID'])) {
1139 $_SESSION['UserFormID'] = null;
1141 $iDBSessCloseDB = false;
1142 $_SESSION['ShowActHidden'] = "no";
1143 require($SettDir['inc'].'prelogin.php');
1144 session_write_close();
1147 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
1148 session_name($Settings['sqltable']."sess");
1149 if (version_compare(phpversion(), '7.0', '<')) {
1153 'use_trans_sid' => false,
1154 'use_cookies' => true,
1155 'use_only_cookies' => true,
1156 'gc_probability' => 1,
1157 'gc_divisor' => 100,
1158 'gc_maxlifetime' => 1440,
1159 //'hash_function' => 1,
1160 //'hash_bits_per_character' => 6,
1161 'name' => $Settings['sqltable']."sess",
1164 if (!isset($_SESSION['UserFormID'])) {
1165 $_SESSION['UserFormID'] = null;
1167 $iDBSessCloseDB = true;
1168 output_reset_rewrite_vars();
1169 //@register_shutdown_function("session_write_close");
1170 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
1171 if (!in_array("ini_set", $disfunc)) {
1172 // Set user agent if ini_set is available and HTTP requests are required.
1173 $iverstring = $Settings['hideverinfohttp'] === "on" ?
"FR 0.0.0 ".$VER2[2]." 0" : $VER2[1]." ".$VER1[0].".".$VER1[1].".".$VER1[2]." ".$VER2[2]." ".$SubVerN;
1175 $qstrtest = htmlentities($Settings['qstr'], ENT_QUOTES
, $Settings['charset']);
1176 $qseptest = htmlentities($Settings['qsep'], ENT_QUOTES
, $Settings['charset']);
1178 $isiteurl = $Settings['idburl'] . url_maker($exfile['index'], $Settings['file_ext'], "act=view", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index']);
1180 @ini_set
("user_agent", "Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")");
1182 if (function_exists("stream_context_create")) {
1187 "Accept-Language: *\r\n" .
1188 "User-Agent: Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")\r\n" .
1190 "Connection: keep-alive\r\n" .
1191 "Referer: ".$isiteurl."\r\n" .
1192 "From: ".$isiteurl."\r\n" .
1193 "Via: ".$_SERVER['REMOTE_ADDR']."\r\n" .
1194 "Forwarded: ".$_SERVER['REMOTE_ADDR']."\r\n" .
1195 "X-Real-IP: ".$_SERVER['REMOTE_ADDR']."\r\n" .
1196 "X-Forwarded-For: ".$_SERVER['REMOTE_ADDR']."\r\n" .
1197 "X-Forwarded-Host: ".$URLsTest['host']."\r\n" .
1198 "X-Forwarded-Proto: ".$URLsTest['scheme']."\r\n" .
1199 "Board-Unique-ID: ".$Settings['BoardUUID']."\r\n" .
1200 "Client-IP: ".$_SERVER['REMOTE_ADDR']."\r\n"
1203 $icontext = stream_context_create($iopts);
1205 function file_get_contents_alt($filename, $use_include_path = null, $offset = -1, $maxlen = null)
1208 return $maxlen !== null
1209 ?
file_get_contents($filename, $use_include_path, $icontext, $offset, $maxlen)
1210 : file_get_contents($filename, $use_include_path, $icontext, $offset);
1214 $iDBVerName = $VerCheckName."|".$VER2[1]."|".$VER1[0].".".$VER1[1].".".$VER1[2]."|".$VER2[2]."|".$SubVerN;
1216 This way checks iDB version by sending the iDBVerName to the iDB Version Checker.
1217 $Settings['vercheck'] = 1;
1218 This way checks iDB version by sending the board url to the iDB Version Checker.
1219 $Settings['vercheck'] = 2;
1221 if (!isset($Settings['vercheck'])) {
1222 $Settings['vercheck'] = 2;
1224 if ($Settings['vercheck'] != 1 &&
1225 $Settings['vercheck'] != 2) {
1226 $Settings['vercheck'] = 2;
1228 if ($Settings['vercheck'] === 2) {
1229 if ($_GET['act'] == "vercheckxsl") {
1230 if (stristr($_SERVER['HTTP_ACCEPT'], "application/xml")) {
1231 header("Content-Type: application/xml; charset=".$Settings['charset']);
1233 header("Content-Type: text/xml; charset=".$Settings['charset']);
1235 xml_doc_start("1.0", $Settings['charset']);
1237 <xsl
:stylesheet version
="1.0" xmlns
:xsl
="http://www.w3.org/1999/XSL/Transform">
1239 <xsl
:template match
="/">
1240 <html xsl
:version
="1.0" xmlns
:xsl
="http://www.w3.org/1999/XSL/Transform" xmlns
="http://www.w3.org/1999/xhtml">
1241 <body style
="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
1242 <xsl
:for-each select
="versioninfo/version">
1243 <div style
="background-color:teal;color:white;padding:4px">
1244 <span style
="font-weight:bold"><xsl
:value
-of select
="vname"/></span
>
1246 <div style
="margin-left:20px;margin-bottom:1em;font-size:10pt">
1247 <span style
="font-style:italic">
1248 Board Name
: <a href
="<?php echo url_maker($exfile['index'], $Settings['file_ext'], "act
=view
", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index']); ?>"><xsl
:value
-of select
="title"/></a
></span
>
1256 <?php
gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1257 session_write_close();
1260 if ($_GET['act'] == "versioninfo") {
1261 if (stristr($_SERVER['HTTP_ACCEPT'], "application/xml")) {
1262 header("Content-Type: application/xml; charset=".$Settings['charset']);
1264 header("Content-Type: text/xml; charset=".$Settings['charset']);
1266 xml_doc_start("1.0", $Settings['charset']);
1267 echo '<?xml-stylesheet type="text/xsl" href="'.url_maker($exfile['index'], $Settings['file_ext'], "act=vercheckxsl", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index']).'"?>'."\n"; ?
>
1269 <!DOCTYPE versioninfo
[
1270 <!ELEMENT
versioninfo (version
*)>
1271 <!ELEMENT
version (charset
,title
,name
,vname
)>
1272 <!ELEMENT
charset (#PCDATA)>
1273 <!ELEMENT
title (#PCDATA)>
1274 <!ELEMENT
name (#PCDATA)>
1275 <!ELEMENT
vname (#PCDATA)>
1281 <charset
><?php
echo $Settings['charset']; ?
></charset
>
1282 <title
><?php
echo $Settings['board_name']; ?
></title
>
1283 <?php
echo "<name>".$iDBVerName."</name>\n"; ?
>
1284 <vname
><?php
echo $VerCheckName; ?
> Version Checker
</vname
>
1288 <?php
gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1289 session_write_close();
1293 if ($_GET['act'] == "status") {
1294 $_GET['act'] = "view";
1295 $_GET['status'] = null;
1297 $statusCodes = array(
1298 100 => "100 Continue",
1299 101 => "101 Switching Protocols",
1300 102 => "102 Processing",
1301 103 => "103 Early Hints",
1303 201 => "201 Created",
1304 202 => "202 Accepted",
1305 203 => "203 Non-Authoritative Information",
1306 204 => "204 No Content",
1307 205 => "205 Reset Content",
1308 206 => "206 Partial Content",
1309 207 => "207 Multi-Status",
1310 208 => "208 Already Reported",
1311 226 => "226 IM Used",
1312 300 => "300 Multiple Choices",
1313 301 => "301 Moved Permanently",
1315 303 => "303 See Other",
1316 304 => "304 Not Modified",
1317 305 => "305 Use Proxy",
1318 306 => "306 (Unused)",
1319 307 => "307 Temporary Redirect",
1320 308 => "308 Permanent Redirect",
1321 400 => "400 Bad Request",
1322 401 => "401 Unauthorized",
1323 402 => "402 Payment Required",
1324 403 => "403 Forbidden",
1325 404 => "404 Not Found",
1326 405 => "405 Method Not Allowed",
1327 406 => "406 Not Acceptable",
1328 407 => "407 Proxy Authentication Required",
1329 408 => "408 Request Timeout",
1330 409 => "409 Conflict",
1332 411 => "411 Length Required",
1333 412 => "412 Precondition Failed",
1334 413 => "413 Payload Too Large",
1335 414 => "414 URI Too Long",
1336 415 => "415 Unsupported Media Type",
1337 416 => "416 Range Not Satisfiable",
1338 417 => "417 Expectation Failed",
1339 418 => "418 I'm a teapot",
1340 421 => "421 Misdirected Request",
1341 422 => "422 Unprocessable Entity",
1342 423 => "423 Locked",
1343 424 => "424 Failed Dependency",
1344 425 => "425 Too Early",
1345 426 => "426 Upgrade Required",
1346 428 => "428 Precondition Required",
1347 429 => "429 Too Many Requests",
1348 431 => "431 Request Header Fields Too Large",
1349 451 => "451 Unavailable For Legal Reasons",
1350 500 => "500 Internal Server Error",
1351 501 => "501 Not Implemented",
1352 502 => "502 Bad Gateway",
1353 503 => "503 Service Unavailable",
1354 504 => "504 Gateway Timeout",
1355 505 => "505 HTTP Version Not Supported",
1356 506 => "506 Variant Also Negotiates",
1357 507 => "507 Insufficient Storage",
1358 508 => "508 Loop Detected",
1359 510 => "510 Not Extended",
1360 511 => "511 Network Authentication Required"
1363 if ($_GET['act'] == "status") {
1364 // Check if 'status' is set and valid, otherwise default to 200
1365 if (!isset($_GET['status']) ||
!array_key_exists((int)$_GET['status'], $statusCodes)) {
1366 $_GET['status'] = 200; // Default to 200 OK
1368 $_GET['status'] = (int)$_GET['status']; // Cast to int if valid
1374 <title
><?php
echo $statusCodes[$_GET['status']]; ?
></title
>
1375 <meta charset
="UTF-8">
1376 <meta name
="author" content
="Null">
1377 <meta name
="keywords" content
="Null">
1378 <meta name
="description" content
="Null">
1379 <meta name
="viewport" content
="width=device-width, initial-scale=1.0">
1382 background
-color
: black
;
1393 text
-decoration
: none
;
1402 <td
><a href
="index.php?act=View"><?php
echo $statusCodes[$_GET['status']]; ?
></a
></td
>
1408 $urlstatus = $_GET['status'];
1409 gzip_page($Settings['use_gzip'], $GZipEncode['Type']); // Assuming gzip_page function exists
1410 session_write_close();
1413 if ($Settings['vercheck'] === 1) {
1414 if ($_GET['act'] == "versioninfo") {
1415 header("Content-Type: text/plain; charset=UTF-8");
1416 header("Location: ".$VerCheckURL."&name=".urlencode($iDBVerName));
1418 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1419 session_write_close();
1423 if ($_GET['act'] == "homepage") {
1424 header("Content-Type: text/plain; charset=UTF-8");
1425 header("Location: ".$Settings['weburl']);
1427 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1428 session_write_close();
1431 if ($_GET['act'] == "bsdl" ||
$_GET['act'] == "BSDL" ||
$_GET['act'] == "license" ||
1432 $_GET['act'] == "LICENSE" ||
$_GET['act'] == "License") {
1433 $_GET['act'] = "bsd";
1435 if ($_GET['act'] == "bsd") {
1436 header("Content-Type: text/plain; charset=".$Settings['charset']);
1438 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1441 if ($_GET['act'] == "README" ||
$_GET['act'] == "ReadME") {
1442 $_GET['act'] = "readme";
1444 if ($_GET['act'] == "readme" ||
$_GET['act'] == "ReadMe") {
1445 header("Content-Type: text/plain; charset=".$Settings['charset']);
1447 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1450 if ($_GET['act'] == "js" ||
$_GET['act'] == "javascript") {
1451 header("Content-Script-Type: text/javascript");
1452 if (stristr($_SERVER['HTTP_ACCEPT'], "application/x-javascript")) {
1453 header("Content-Type: application/x-javascript; charset=".$Settings['charset']);
1455 if (stristr($_SERVER['HTTP_ACCEPT'], "application/javascript")) {
1456 header("Content-Type: application/javascript; charset=".$Settings['charset']);
1458 header("Content-Type: text/javascript; charset=".$Settings['charset']);
1461 require($SettDir['inc'].'javascript.php');
1462 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1465 $Settings['use_captcha'] = "off";
1466 /*if($Settings['use_captcha']=="on") {
1467 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
1468 if($Settings['captcha_clean']=="on") { ob_clean(); }
1469 require($SettDir['inc']."captcha.php");
1470 $aFontDir = dirname(__FILE__)."/inc/fonts/";
1471 $aFonts = array($aFontDir.'VeraBd.ttf', $aFontDir.'VeraBI.ttf', $aFontDir.'VeraIt.ttf', $aFontDir.'Vera.ttf');
1472 $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
1473 $RNumSize = rand(7,17); $i=0; $RandNum = null;
1474 while ($i <= $RNumSize) {
1475 $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
1476 $RandNum=strtoupper($RandNum);
1477 $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
1478 $oPhpCaptcha->UseColour(true);
1479 $oPhpCaptcha->Create(); session_write_close(); die(); } }*/
1480 require($SettDir['inc'].'groupsetup.php');
1481 if ($Settings['board_offline'] == "on" && $GroupInfo['CanViewOffLine'] != "yes") {
1482 header("Content-Type: text/plain; charset=".$Settings['charset']);
1483 sql_free_result($peresult);
1485 if (!isset($Settings['offline_text'])) {
1486 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp.";
1488 if (isset($Settings['offline_text'])) {
1489 echo $Settings['offline_text'];
1491 //echo "\n".sql_errorno($SQLStat);
1492 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
1493 session_write_close();
1497 if (!isset($_SESSION['iDBDateFormat'])) {
1498 if (isset($Settings['idb_date_format'])) {
1499 $_SESSION['iDBDateFormat'] = $Settings['idb_date_format'];
1500 if (!isset($Settings['idb_date_format'])) {
1501 $_SESSION['iDBDateFormat'] = "g:i A";
1505 if (!isset($_SESSION['iDBTimeFormat'])) {
1506 if (isset($Settings['idb_time_format'])) {
1507 $_SESSION['iDBTimeFormat'] = $Settings['idb_time_format'];
1508 if (!isset($Settings['idb_time_format'])) {
1509 $_SESSION['iDBTimeFormat'] = "F j Y";
1514 if (!isset($_SESSION['UserTimeZone'])) {
1515 if (isset($Settings['DefaultTimeZone'])) {
1516 $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
1517 if (!isset($Settings['DefaultTimeZone'])) {
1518 $_SESSION['UserTimeZone'] = date_default_timezone_get();
1522 $usertz = new DateTimeZone($_SESSION['UserTimeZone']);
1523 $usercurtime->setTimestamp($defcurtime->getTimestamp());
1524 $usercurtime->setTimezone($usertz);
1526 if (isset($_SESSION['MemberName']) ||
1527 isset($_COOKIE['MemberName'])) {
1528 $_SESSION['GuestName'] = null;
1529 $_COOKIE['GuestName'] = null;
1531 if (!isset($_SESSION['MemberName']) && !isset($_COOKIE['MemberName'])) {
1532 if (!isset($_SESSION['GuestName']) && isset($_COOKIE['GuestName'])) {
1533 $_SESSION['GuestName'] = $_COOKIE['GuestName'];
1536 if (!isset($_SESSION['LastPostTime'])) {
1537 $_SESSION['LastPostTime'] = "0";
1540 if (!isset($_SESSION['Theme'])) {
1541 $_SESSION['Theme'] = null;
1543 if (!isset($_GET['theme'])) {
1544 $_GET['theme'] = null;
1546 if (!isset($_POST['theme'])) {
1547 $_POST['theme'] = null;
1549 if (!isset($_GET['skin'])) {
1550 $_GET['skin'] = null;
1552 if (!isset($_POST['skin'])) {
1553 $_POST['skin'] = null;
1555 if (!isset($_GET['style'])) {
1556 $_GET['style'] = null;
1558 if (!isset($_POST['style'])) {
1559 $_POST['style'] = null;
1561 if (!isset($_GET['css'])) {
1562 $_GET['css'] = null;
1564 if (!isset($_POST['css'])) {
1565 $_POST['css'] = null;
1567 if ($_GET['theme'] == null) {
1568 if ($_POST['theme'] != null) {
1569 $_GET['theme'] = $_POST['theme'];
1571 if ($_POST['skin'] != null) {
1572 $_GET['theme'] = $_POST['skin'];
1574 if ($_POST['style'] != null) {
1575 $_GET['theme'] = $_POST['style'];
1577 if ($_POST['css'] != null) {
1578 $_GET['theme'] = $_POST['css'];
1580 if ($_GET['skin'] != null) {
1581 $_GET['theme'] = $_GET['skin'];
1583 if ($_GET['style'] != null) {
1584 $_GET['theme'] = $_GET['style'];
1586 if ($_GET['css'] != null) {
1587 $_GET['theme'] = $_GET['css'];
1590 if ($Settings['SQLThemes'] == "off") {
1591 if ($_GET['theme'] != null) {
1592 $_GET['theme'] = chack_themes($_GET['theme']);
1593 if ($_GET['theme'] == "../" ||
$_GET['theme'] == "./") {
1594 $_GET['theme'] = $Settings['DefaultTheme'];
1595 $_SESSION['Theme'] = $Settings['DefaultTheme'];
1597 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
1598 if ($_SESSION['UserGroup'] != $Settings['GuestGroup']) {
1599 $NewDay = $utccurtime->getTimestamp();
1600 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
1601 sql_query($qnewskin, $SQLStat);
1603 /* The file Theme Exists */
1605 $_GET['theme'] = $Settings['DefaultTheme'];
1606 $_SESSION['Theme'] = $Settings['DefaultTheme'];
1607 /* The file Theme Dose Not Exists */
1610 if ($_GET['theme'] == null) {
1611 if ($_SESSION['Theme'] != null) {
1612 $OldTheme = $_SESSION['Theme'];
1613 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
1614 if ($_SESSION['UserGroup'] != $Settings['GuestGroup']) {
1615 if ($OldTheme != $_SESSION['Theme']) {
1616 $NewDay = $utccurtime->getTimestamp();
1617 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
1618 sql_query($qnewskin, $SQLStat);
1621 $_GET['theme'] = $_SESSION['Theme'];
1623 if ($_SESSION['Theme'] == null) {
1624 $_SESSION['Theme'] = $Settings['DefaultTheme'];
1625 $_GET['theme'] = $Settings['DefaultTheme'];
1628 $PreSkin['skindir1'] = $_SESSION['Theme'];
1629 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
1630 require($SettDir['themes'].$_GET['theme']."/settings.php");
1632 if ($Settings['SQLThemes'] == "on") {
1633 if ($_GET['theme'] == null && $_SESSION['Theme'] == null) {
1634 $_GET['theme'] = $Settings['DefaultTheme'];
1635 $_SESSION['Theme'] = $Settings['DefaultTheme'];
1637 if ($_GET['theme'] != null) {
1638 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
1641 if ($_GET['theme'] == null) {
1642 if ($_SESSION['Theme'] != null) {
1643 $themenum = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])), $SQLStat);
1644 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme']));
1647 $themeresult = sql_query($themequery, $SQLStat);
1648 if ($themenum <= 0) {
1649 $_GET['theme'] = $Settings['DefaultTheme'];
1650 $_SESSION['Theme'] = $Settings['DefaultTheme'];
1651 if ($_SESSION['UserGroup'] != $Settings['GuestGroup']) {
1652 $NewDay = $utccurtime->getTimestamp();
1653 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
1654 sql_query($qnewskin, $SQLStat);
1656 $themenum = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])), $SQLStat);
1657 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
1658 $themeresult = sql_query($themequery, $SQLStat);
1660 if ($_GET['theme'] == null) {
1661 if ($_SESSION['Theme'] != null) {
1662 $_GET['theme'] = $_SESSION['Theme'];
1665 if ($_SESSION['UserGroup'] != $Settings['GuestGroup']) {
1666 $NewDay = $utccurtime->getTimestamp();
1667 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
1668 sql_query($qnewskin, $SQLStat);
1671 require($SettDir['inc'].'sqlthemes.php');
1672 sql_free_result($themeresult);
1674 $_SESSION['Theme'] = $_GET['theme'];
1675 function get_theme_values($matches)
1678 $return_text = null;
1679 if (isset($ThemeSet[$matches[1]])) {
1680 $return_text = $ThemeSet[$matches[1]];
1682 if (!isset($ThemeSet[$matches[1]])) {
1683 $return_text = null;
1685 return $return_text;
1687 foreach ($ThemeSet as $key => $value) {
1688 if (isset($ThemeSet[$key])) {
1689 $ThemeSet[$key] = preg_replace("/%%/s", "{percent}p", $ThemeSet[$key]);
1690 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}T/s", "get_theme_values", $ThemeSet[$key]);
1691 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}e/s", "get_env_values", $ThemeSet[$key]);
1692 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}i/s", "get_server_values", $ThemeSet[$key]);
1693 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}s/s", "get_setting_values", $ThemeSet[$key]);
1694 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}t/s", "get_time", $ThemeSet[$key]);
1695 $ThemeSet[$key] = preg_replace("/\{percent\}p/s", "%", $ThemeSet[$key]);
1698 if (!isset($ThemeSet['TableStyle'])) {
1699 $ThemeSet['TableStyle'] = "table";
1701 if (isset($ThemeSet['TableStyle'])) {
1702 if ($ThemeSet['TableStyle'] != "div" &&
1703 $ThemeSet['TableStyle'] != "table") {
1704 $ThemeSet['TableStyle'] = "table";
1707 if (!isset($_SESSION['DBName'])) {
1708 $_SESSION['DBName'] = null;
1710 if ($_SESSION['DBName'] == null) {
1711 $_SESSION['DBName'] = $Settings['sqldb'];
1713 if ($_SESSION['DBName'] != null) {
1714 if ($_SESSION['DBName'] != $Settings['sqldb']) {
1715 redirect("location", $rbasedir.url_maker($exfile['member'], $Settings['file_ext'], "act=logout", $Settings['qstr'], $Settings['qsep'], $prexqstr['member'], $exqstr['member'], false));