<?php
	function logged_in () {
		if (isset($_SESSION['username']) && isset($_SESSION['user_id'])) {
			return true;
		} else {
			return false;
		}
	}
	
	function redirect_to ($url) {
		header("Location: {$url}");
	}

	function getUserById($id){
        $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

        if ($mysqli->connect_errno) {
            echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
            exit();
        }
        $sql = "SELECT * from users WHERE id = $id LIMIT 1";

        $result = mysqli_query($mysqli, $sql);
        return mysqli_fetch_assoc($result);
    }
?>