Compare commits

...

5 commits

8 changed files with 50 additions and 61 deletions

View file

@ -1,5 +1,6 @@
# Custom error pages
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 405 /errors/405.php
ErrorDocument 500 /errors/500.php
ErrorDocument 504 /errors/504.php

18
assets/errors/405.php Normal file
View file

@ -0,0 +1,18 @@
<?php
$COMMONS = "./../../docs/common";
include_once($COMMONS."/header.php");
display_header("405: Method not allowed");
?>
<article>
<h2>405: Method Not Allowed</h2>
<div class="centered-container">
<img src="https://assets.zdenekborovec.cz/upload/39486004aa605167cdda6623a4a3fa6d/7da36b469b34cc1008639612f0c17e21/d077e6ed1bd1a560a718590ae609422c.gif" alt="GIF of a cat shaking its head.">
</div>
</article>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -15,5 +15,6 @@ RewriteRule ^([^\.]+)/$ $1.php
# Custom error pages
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 405 /errors/405.php
ErrorDocument 500 /errors/500.php
ErrorDocument 503 /errors/503.php

View file

@ -149,6 +149,15 @@ function load_blog($conn, $blogId){
$datePosted, $dateEdited, $tags, $comments);
}
// If request is not POST, throw method not allowed
if(strcmp($_SERVER["REQUEST_METHOD"], "POST") != 0)
{
header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/405.php");
include_once($COMMONS."/footer.php");
die();
}
// Check DB connection
if($conn == null){
header($_SERVER["SERVER_PROTOCOL"]." 503 Service Unavailable", true, 503);
@ -183,8 +192,6 @@ $blogPost = load_blog($conn, $blogId);
// If blogpost could not be retieved, display warning and die.
if(!$blogPost) {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404);
//include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");
//include_once($COMMONS."/footer.php");
die();
}
@ -235,60 +242,4 @@ include_once(\"%s\");
$blogPost->address,
addslashes($blogPost->display_comments()),
$COMMONS."/footer.php");
/*
// Display the header with title being the blog name
display_header($blogPost->title);
// Display the blog
$blogPost->display_article();
printf("<hr style=\"border-style: solid;\">");
// Display post comment form.
if(is_null($blogPost->address))
{
printf("
<article>
<h2> Comments: </h2>
<form method=\"post\" action=\"%s\">
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<label for=\"comment_entry\">Write a comment (%s):</label>
<div class=\"centered-container\">
<textarea name=\"comment_entry\" class=\"comment-box\"
tabindex=\"1\"></textarea>
</div>
<input name=\"submit\" type=\"submit\" tabindex=\"2\"
value=\"Send\">
</form>
</article>
",
htmlspecialchars($_SERVER["PHP_SELF"]), $blogId,
isset($_SESSION["current_user"]) ?
$_SESSION["current_user"]->user_name : "Guest");
}
else
{
printf("
<article>
<h2> Comments: </h2>
<form method=\"post\" action=\"%s\">
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<input type=\"hidden\" name=\"address\" value=\"%s\">
<label for=\"comment_entry\">Write a comment (%s):</label>
<div class=\"centered-container\">
<textarea name=\"comment_entry\" class=\"comment-box\"
tabindex=\"1\"></textarea>
</div>
<input name=\"submit\" type=\"submit\" tabindex=\"2\"
value=\"Send\">
</form>
</article>
",
htmlspecialchars($_SERVER["PHP_SELF"]), $blogId, $blogPost->address,
isset($_SESSION["current_user"]) ?
$_SESSION["current_user"]->user_name : "Guest");
}
// Display the blog comments
$blogPost->display_comments();
*/
?>

View file

@ -21,7 +21,7 @@ function display_blog_preview($blogpost_id, $blogpost_addr, $title, $abstract,
else {
printf("
<div class=\"blog-preview\">
<a href=\"http://www.zdenekborovec-dev.cz/blog/article?address=%s\">
<a href=\"http://www.zdenekborovec-dev.cz/blog/article/%s\">
<h3>
%s
</h3>

18
docs/www/errors/405.php Normal file
View file

@ -0,0 +1,18 @@
<?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("405: Method not allowed");
?>
<article>
<h2>405: Method Not Allowed</h2>
<div class="centered-container">
<img src="https://assets.zdenekborovec.cz/upload/39486004aa605167cdda6623a4a3fa6d/7da36b469b34cc1008639612f0c17e21/d077e6ed1bd1a560a718590ae609422c.gif" alt="GIF of a cat shaking its head.">
</div>
</article>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -3,7 +3,7 @@ $COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("403: Forbidden");
display_header("500: Internal Server Error");
?>
<article>

View file

@ -4,7 +4,7 @@ $COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("403: Forbidden");
display_header("503: Service Unavailable");
?>
<article>