added logging out
This commit is contained in:
parent
ca7ee9fba2
commit
1d28eda86a
3 changed files with 55 additions and 4 deletions
|
@ -116,6 +116,10 @@ ul {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#header table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
#footer {
|
#footer {
|
||||||
border-top: double;
|
border-top: double;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
|
@ -123,7 +127,6 @@ ul {
|
||||||
|
|
||||||
.noborder-table td, .noborder-table th {
|
.noborder-table td, .noborder-table th {
|
||||||
border: none;
|
border: none;
|
||||||
text-align: left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-container-right {
|
.image-container-right {
|
||||||
|
|
|
@ -40,6 +40,45 @@ function attempt_sql_connect() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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"])));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 <br>
|
||||||
|
<form method=\"post\" action=%s>
|
||||||
|
<input name=\"get_params\" type=\"hidden\" value=\"%s\">
|
||||||
|
<input name=\"logout\" type=\"submit\" value=\"logout\">
|
||||||
|
</form>
|
||||||
|
<a href=\"http://www.zdenekborovec-dev.cz/deleteaccount/\">
|
||||||
|
Delete account</a>", $_SESSION["current_user"]->user_name,
|
||||||
|
sanitize_input($_SERVER["PHP_SELF"]),
|
||||||
|
sanitize_input($_SERVER["QUERY_STRING"]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return sprintf("<a href=\"http://www.zdenekborovec-dev.cz/login\">Login</a>
|
||||||
|
<br><a href=\"http://www.zdenekborovec-dev.cz/register\">Register</a>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the html document, set headers, begin body and display the default
|
* Start the html document, set headers, begin body and display the default
|
||||||
* navbar.
|
* navbar.
|
||||||
|
@ -62,7 +101,16 @@ function display_header($pageTitle) {
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<div id=\"header\">
|
<div id=\"header\">
|
||||||
<h1> Zdenek Borovec Home Page </h1>
|
<table class=\"noborder-table\">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h1> Zdenek Borovec Home Page </h1>
|
||||||
|
</td>
|
||||||
|
<td style=\"text-align: right; padding-right: 2em;\">
|
||||||
|
%s
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a href=\"http://www.zdenekborovec-dev.cz\">
|
<a href=\"http://www.zdenekborovec-dev.cz\">
|
||||||
|
@ -83,6 +131,6 @@ function display_header($pageTitle) {
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>", $pageTitle);
|
</div>", $pageTitle, construct_account_section());
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -403,7 +403,7 @@ $blogPost = load_blog($conn, $blogId);
|
||||||
|
|
||||||
// If no ID was entered, display warning and die.
|
// If no ID was entered, display warning and die.
|
||||||
if(!$blogPost) {
|
if(!$blogPost) {
|
||||||
display_header("Article not found");
|
display_header("Article not found");
|
||||||
printf("
|
printf("
|
||||||
<article>
|
<article>
|
||||||
<h2>The article you requested doesn't exist.</h2>
|
<h2>The article you requested doesn't exist.</h2>
|
||||||
|
|
Loading…
Reference in a new issue