setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
$conn = null;
return;
}
}
/**
* If user logged out, destroy the session data and delete cookie.
*/
if (isset($_POST["logout"])) {
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Redirect to this page with GET
header(sprintf("Location: %s/?%s",
sanitize_input($_SERVER["PHP_SELF"]),
sanitize_input($_POST["get_params"])));
die();
}
/**
* Construct the available account actions for the header depending on whether
* a user is logged in or not and return it as string.
*/
function construct_account_section(){
if(isset($_SESSION["current_user"])) {
return sprintf("Logged in as %s
Delete account", $_SESSION["current_user"]->user_name,
sanitize_input($_SERVER["PHP_SELF"]),
sanitize_input($_SERVER["QUERY_STRING"]));
}
else {
return sprintf("Login Register");
}
}
/**
* Start the html document, set headers, begin body and display the default
* navbar.
* nad tags will be left open, to close them
* in the default way include footer.php
* This should be the first function to write any text outside of debugging
* purposes.
*/
function display_header($pageTitle) {
global $header_displayed;
if($header_displayed){
return;
}
$header_displayed = true;
printf("
%s