bindValue(':username', $username); $query->bindValue(':password', $password); $query->execute() or error(db_error($query)); if($user = $query->fetch()) { return $mod = Array( 'id' => $user['id'], 'type' => $user['type'], 'username' => $username, 'password' => $password, 'hash' => isset($_SESSION['mod']['hash']) ? $_SESSION['mod']['hash'] : mkhash(), 'boards' => explode(',', $user['boards']) ); } else return false; } function setCookies() { global $mod, $config; if(!$mod) error('setCookies() was called for a non-moderator!'); // $config['cookies']['mod'] contains username:hash setcookie($config['cookies']['mod'], $mod['username'] . ':' . $mod['hash'], time()+$config['cookies']['expire'], $config['cookies']['jail']?$config['cookies']['path']:'/', null, false, true); // Put $mod in the session $_SESSION['mod'] = $mod; // Lock sessions to IP addresses if($config['mod']['lock_ip']) $_SESSION['mod']['ip'] = $_SERVER['REMOTE_ADDR']; } function destroyCookies() { global $config; // Delete the cookies setcookie($config['cookies']['mod'], 'deleted', time()-$config['cookies']['expire'], $config['cookies']['jail']?$config['cookies']['path']:'/', null, false, true); // Unset the session unset($_SESSION['mod']); } function create_pm_header() { global $mod; $query = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1"); $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); if($pm = $query->fetch()) { return 'You have an unread PM' . ($query->rowCount() > 1 ? ', plus ' . ($query->rowCount()-1) . ' more waiting' : '') . '.'; } return false; } function modLog($action, $_board=null) { global $mod, $board; $query = prepare("INSERT INTO `modlogs` VALUES (:id, :ip, :board, :time, :text)"); $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':time', time(), PDO::PARAM_INT); $query->bindValue(':text', $action); if(isset($_board)) $query->bindValue(':board', $_board); elseif(isset($board)) $query->bindValue(':board', $board['id']); else $query->bindValue(':board', null, PDO::PARAM_NULL); $query->execute() or error(db_error($query)); } if(isset($_COOKIE[$config['cookies']['mod']]) && isset($_SESSION['mod']) && is_array($_SESSION['mod'])) { // Should be username:session hash $cookie = explode(':', $_COOKIE[$config['cookies']['mod']]); if(count($cookie) != 2) { destroyCookies(); error($config['error']['malformed']); } // Validate session if( $cookie[0] != $_SESSION['mod']['username'] || $cookie[1] != $_SESSION['mod']['hash']) { // Malformed cookies destroyCookies(); error($config['error']['malformed']); } // Open connection sql_open(); // Check username/password if(!login($_SESSION['mod']['username'], $_SESSION['mod']['password'], false)) { destroyCookies(); error($config['error']['invalidafter']); } } // Generates a