Re-worded thinger
[specialops2.git] / con.php
blobf87e6b0a862cbcad5456ef75b78f3a8fe23419cb
1 <?php
2 // $Id$
4 if ( version_compare(PHP_VERSION, '5.0', '<') ) {
5 header('HTTP/1.1 500 Internal Server Error');
6 die('PHP 5.0 or higher is required.');
9 error_reporting(E_ALL|E_STRICT);
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 {}
20 // SPL exception names only in >=5.1
21 if (version_compare(PHP_VERSION, '5.1', '<')) {
22 class OutOfBoundsException extends Exception {}
23 class RuntimeException extends Exception {}
24 class LengthException extends Exception {}
28 // Keep these numbers in order, and don't change them unless your DB is empty
29 define('LVL_RESTRICTED', 0);
30 define('LVL_USER', 10);
31 define('LVL_ADMIN', 60);
32 define('LVL_DEV', 70);
34 // Class loader
35 function __autoload($classname)
37 require 'lib/class.'.$classname.'.php';
41 // Debug settings
42 if ( !isset($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'] )
43 define('DEVELOPER', 1);
46 // Exception handler
47 if ( defined('DEVELOPER') ) {
48 ob_start();
50 function e_handler($exception)
52 header('HTTP/1.1 500 Internal Server Error');
53 header('Content-Type: text/html; charset=UTF-8');
54 echo '<pre class="error">',$exception->__toString(),'</pre>';
55 exit;
57 } else {
58 function e_handler($exception)
60 restore_error_handler();
61 ini_set('display_errors', 0);
63 if ( !headers_sent() ) {
64 header('HTTP/1.1 500 Internal Server Error');
65 header('Content-Type: text/html; charset=UTF-8');
68 echo '<p class="error">An unrecoverable error has been detected and page execution has been halted.</p>',"\n",
69 '<p class="error">Try reloading the page, or contact the site owner if this happens consistently.</p>';
70 trigger_error($exception->getMessage(), E_USER_ERROR);
71 exit;
74 set_exception_handler('e_handler');
77 // Database Auth+object
78 require 'mysql_ident.php';
80 if ( defined('DEVELOPER') )
81 $DB = new debugmysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
82 else
83 $DB = new mysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
85 if ( mysqli_connect_errno() ) {
86 header('Location: servererror');
90 // Login cookie setting hack
91 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
92 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
96 // User Auth+object
97 if ( isset($_POST['logout']) ) {
99 setcookie('u', null, 1);
100 setcookie('p', null, 1);
101 unset($_COOKIE);
102 $user = new anonuser;
104 } elseif ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
106 $q = $DB->query('SELECT `userid` FROM `users`
107 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'
108 AND (`password` = AES_ENCRYPT(\''.$DB->escape_string($_COOKIE['p']).'\', `reg_ip`) OR `password` IS NULL)');
110 if ( 1 === $q->num_rows ) {
111 setcookie('u', $_COOKIE['u'], time()+86400*7);
112 setcookie('p', $_COOKIE['p'], time()+86400*7);
114 if ( isset($_POST['login']) )
115 $DB->query('UPDATE `users` SET `last_login_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
116 WHERE `alias` = \''.$DB->escape_string($_COOKIE['u']).'\'');
118 if ( empty($prefetch) )
119 $prefetch = array();
121 $user = new authuser($q->fetch_object()->userid, $prefetch);
122 } else {
123 setcookie('u', null, 1);
124 setcookie('p', null, 1);
126 $user = new anonuser;
128 } else {
129 $user = new anonuser;
132 $page = new page;