Created
July 13, 2015 20:48
-
-
Save Archigos/fa4ea53177fc5d865a5e to your computer and use it in GitHub Desktop.
Create 'Pretty' Error Pages inside projects
This file contains 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 | |
// Turn Off Displayed Errors | |
ini_set('display_errors', false); | |
// Handle Errors Our Way | |
// You Can Replace 'shutdown_handler' With Any Name, But | |
// Must Match Function Below | |
register_shutdown_function('shutdown_handler'); | |
function shutdown_handler() { | |
// Verify There's An Error Before Attempting To Display Anything, | |
// Otherwise Ignore And Display NULL | |
if(false === is_null($error = error_get_last())) { | |
// Extraction Gives You Access To $type, $message, $file, $line | |
extract($error); | |
?> | |
<title>Error Type <?= $type; ?></title> | |
<style> | |
body { | |
position: absolute; | |
height: 100vh; | |
width: 100vw; | |
margin: 0; | |
padding: 0; | |
font: 14px Tahoma; | |
background: #333333; | |
} | |
body > :not(.hideEverything) { | |
display: none; | |
} | |
.center { | |
position: relative; | |
height: calc(100% - 50px); | |
color: #FFFFFF; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-direction: column; | |
} | |
.centerBox, h1, h3 { | |
min-width: 400px; | |
font-size: 12px; | |
box-shadow: 0 0 5px #CCCCCC; | |
} | |
.centerBox { | |
padding: 20px; | |
text-shadow: 1px 1px #333333; | |
background: #111111; | |
border-radius: 15px; | |
} | |
h1, h3 { | |
margin: 15px 0; | |
padding: 10px; | |
background: #A72C01; | |
border-radius: 10px; | |
text-align: center; | |
} | |
h2 { | |
padding-bottom: 5px; | |
font-size: 12px; | |
border-bottom: 1px solid #CCCCCC; | |
} | |
h3 { | |
background: #382C74; | |
} | |
p { | |
margin: -5px 0 25px 0; | |
} | |
a:link, a:visited, a:hover, a:active { | |
color: #CCCCCC; | |
text-decoration: none; | |
} | |
.returnHome { | |
height: 50px; | |
text-align: center; | |
} | |
</style> | |
<body> | |
<!-- Using "body > :not(.hideEverything)" CSS Above Allows Any Rendered Parts Of The Page To Be Hidden --> | |
<div class="hideEverything"> | |
<div class="center"> | |
<h1>Fatal Error - Type: <?= $type ?></h1> | |
<div class="centerBox"> | |
<h2>Error</h2> | |
<p><?= $message ?></p> | |
<h2>File</h2> | |
<!-- | |
Allow The File To Be Opened Directly In Sublime Text On Mac, | |
Windows Users: See Original Write Up Here: http://archigos.ictcsc.com/development-integration-custom-web-protocols-and-other-stuff-2 | |
And The Follow Up Here: http://archigos.ictcsc.com/random-stuff-plus-some-updates-to-the-custom-protocols | |
For How To Set Up Custom Protocols Like Subl. | |
--> | |
<p><a href="subl://<?= urlencode($file) ?>"><?= $file ?></a></p> | |
<!-- Remove Anchor Tag Above If You Have Security Concerns Or Don't Want To Utilize Sublime Text In This Way --> | |
<h2>Line</h2> | |
<p><?= $line ?></p> | |
</div> | |
<h3>If you're not the webmaster, feel free to ignore this.</h3> | |
</div> | |
<div class="returnHome"> | |
<a href="/">⇒ Attempt to Return Home ⇐</a> | |
</div> | |
</div> | |
</body> | |
<?php | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment