4 error_reporting(E_ALL|E_STRICT
);
6 if ( version_compare(PHP_VERSION
, '5.0', '<') ) {
7 header('HTTP/1.1 500 Internal Server Error');
8 die('PHP 5.0 or higher is required.');
11 define('CLOCK', microtime(1));
12 define('SO2VER', '$Rev$');
15 // Empty exception types
16 class InvalidInputException
extends Exception
{ }
17 class DatabaseException
extends Exception
{ }
18 class RateLimitException
extends Exception
{ }
19 // SPL compat for <5.1
20 if (version_compare(PHP_VERSION
, '5.1', '<')) {
21 class RuntimeException
extends Exception
{ }
25 // Don't change these numbers on a running board
26 define('LVL_RESTRICTED', 0);
27 define('LVL_USER', 10);
28 define('LVL_ADMIN', 60);
29 define('LVL_DEV', 70);
32 function __autoload($classname)
34 require 'lib/class.'.$classname.'.php';
39 if ( !isset($_SERVER['REMOTE_ADDR']) ||
$_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'] )
40 define('DEVELOPER', 1);
44 if ( defined('DEVELOPER') ) {
47 function e_handler($exception)
49 header('HTTP/1.1 500 Internal Server Error');
50 header('Content-Type: text/html; charset=UTF-8');
51 echo '<pre class="error">',$exception->__toString(),'</pre>';
55 function e_handler($exception)
57 restore_error_handler();
58 ini_set('display_errors', 0);
60 if ( !headers_sent() ) {
61 header('HTTP/1.1 500 Internal Server Error');
62 header('Content-Type: text/html; charset=UTF-8');
65 echo '<p class="error">An unrecoverable error has been detected and page execution has been halted.</p>',"\n",
66 '<p class="error">Try reloading the page, or contact the site owner if this happens again.</p>';
67 trigger_error($exception->getMessage(), E_USER_ERROR
);
71 set_exception_handler('e_handler');
74 // Database Auth+object
75 require 'mysql_ident.php';
77 if ( defined('DEVELOPER') )
78 $DB = new debugmysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
80 $DB = new mysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
82 if ( mysqli_connect_errno() )
86 // Login cookie setting hack
87 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
88 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
93 if ( isset($_POST['logout']) ) {
95 setcookie('u', null, 1);
96 setcookie('p', null, 1);
100 } elseif ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
102 $q = $DB->query('SELECT `userid` FROM `users`
103 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'
104 AND `password` = AES_ENCRYPT(\''.$DB->escape_string($_COOKIE['p']).'\', `reg_ip`)');
106 if ( 1 === $q->num_rows
) {
107 setcookie('u', $_COOKIE['u'], time()+
86400*7);
108 setcookie('p', $_COOKIE['p'], time()+
86400*7);
110 if ( isset($_POST['login']) )
111 $DB->query('UPDATE `users` SET `last_login_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
112 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'');
114 if ( empty($prefetch) )
117 $user = new authuser($q->fetch_object()->userid
, $prefetch);
119 setcookie('u', null, 1);
120 setcookie('p', null, 1);
122 $user = new anonuser
;
125 $user = new anonuser
;
130 if ( defined('DEVELOPER') )
131 $page = new debugpage
;