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
{ }
22 class LengthException
extends Exception
{ }
26 // Don't change these numbers on a running board
27 define('LVL_RESTRICTED', 0);
28 define('LVL_USER', 10);
29 define('LVL_ADMIN', 60);
30 define('LVL_DEV', 70);
33 function __autoload($classname)
35 require 'lib/class.'.$classname.'.php';
40 if ( !isset($_SERVER['REMOTE_ADDR']) ||
$_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'] )
41 define('DEVELOPER', 1);
45 if ( defined('DEVELOPER') ) {
48 function e_handler($exception)
50 header('HTTP/1.1 500 Internal Server Error');
51 header('Content-Type: text/html; charset=UTF-8');
52 echo '<pre class="error">',$exception->__toString(),'</pre>';
56 function e_handler($exception)
58 restore_error_handler();
59 ini_set('display_errors', 0);
61 if ( !headers_sent() ) {
62 header('HTTP/1.1 500 Internal Server Error');
63 header('Content-Type: text/html; charset=UTF-8');
66 echo '<p class="error">An unrecoverable error has been detected and page execution has been halted.</p>',"\n",
67 '<p class="error">Try reloading the page, or contact the site owner if this happens again.</p>';
68 trigger_error($exception->getMessage(), E_USER_ERROR
);
72 set_exception_handler('e_handler');
75 // Database Auth+object
76 require 'mysql_ident.php';
78 if ( defined('DEVELOPER') )
79 $DB = new debugmysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
81 $DB = new mysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
83 if ( mysqli_connect_errno() ) {
84 header('Location: servererror');
88 // Login cookie setting hack
89 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
90 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
95 if ( isset($_POST['logout']) ) {
97 setcookie('u', null, 1);
98 setcookie('p', null, 1);
100 $user = new anonuser
;
102 } elseif ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
104 $q = $DB->query('SELECT `userid` FROM `users`
105 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'
106 AND `password` = AES_ENCRYPT(\''.$DB->escape_string($_COOKIE['p']).'\', `reg_ip`)');
108 if ( 1 === $q->num_rows
) {
109 setcookie('u', $_COOKIE['u'], time()+
86400*7);
110 setcookie('p', $_COOKIE['p'], time()+
86400*7);
112 if ( isset($_POST['login']) )
113 $DB->query('UPDATE `users` SET `last_login_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
114 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'');
116 if ( empty($prefetch) )
119 $user = new authuser($q->fetch_object()->userid
, $prefetch);
121 setcookie('u', null, 1);
122 setcookie('p', null, 1);
124 $user = new anonuser
;
127 $user = new anonuser
;