Created
October 30, 2014 06:01
-
-
Save benlk/aaba07b6ba7da7d01f46 to your computer and use it in GitHub Desktop.
An improved 404 page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* I see lots of cute 404 pages with funny messages. | |
* Most 404 pages don't tell you what link you used to get to the 404, | |
* and they don't really give you options on how to get to where you want to go | |
* other than "Click here to return to our front page." | |
* That approach is as bad as http://xkcd.com/869/ | |
* Sadly, this page doesn't do anything fancy like list other articles. | |
* Using DuckDuckGo because it's better than Google. | |
*/ | |
header("HTTP/1.0 404 Not Found"); | |
$suggest = false; | |
if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != "") { | |
$suggest = true; | |
$suggestion = $_SERVER['REQUEST_URI']; // Gives people the URL they visited so they know what to search for. | |
} else { | |
$suggestion = ""; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> | |
<style type="text/css"> | |
/* https://stackoverflow.com/questions/9825796/how-to-make-text-vertically-and-horizontally-center-in-an-html-page#9826008 */ | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
width: 100%; | |
font-size: 10px; | |
} | |
body{ | |
display: table; | |
} | |
div { | |
text-align: center; | |
display: table-cell; | |
vertical-align: middle; | |
} | |
#ddg { | |
overflow:hidden;margin:0;padding:0;width:400px;height:40px; | |
} | |
p { | |
font-size: 2em; | |
} | |
.disclaimer { | |
font-size: 1.2em; | |
} | |
.disclaimer a, .disclaimer a:hover, .disclaimer a:active { | |
color: inherit; | |
} | |
</style> | |
<title>Not found</title> | |
</head> | |
<body> | |
<div> | |
<?php if ($suggest === true) { ?> | |
<p>We can't find <?php echo($suggestion); ?> here.</p> | |
<p>What were you looking for?</p> | |
<?php } else { ?> | |
<p>What were you looking for? </p> | |
<?php } ?> | |
<iframe id="ddg" src="http://duckduckgo.com/search.html?site=<?php | |
echo $_SERVER['SERVER_NAME']; // the www.example.com part of the URL | |
?>&prefill=Search this site&focus=yes" frameborder="0"></iframe> | |
<p class="disclaimer">This search box uses <a href="https://duckduckgo.com/about">DuckDuckGo</a>, a privacy-positive search engine.</p> | |
<p><a class="button" href="http://<?php echo $_SERVER['SERVER_NAME']?>">To the homepage!</a></p> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment