This repository was archived by the owner on Mar 29, 2019. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror-handler.php
More file actions
Latest commit
33 lines (27 loc) · 1004 Bytes
/
Copy patherror-handler.php
File metadata and controls
33 lines (27 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php# error-handler.php, by Zash. Part of simple pastebin-thingy.
ob_start('ob_gzhandler');
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$ext = pathinfo($uri, PATHINFO_EXTENSION);
$src = '.' . substr_replace($uri, 'txt', -strlen($ext));
if(file_exists($src)) {
header('Content-Type: text/html; charset=utf8');
switch($ext) {
case'php': # php-syntax highlighting
highlight_file($src);
break;
case'text':
echonl2br(htmlspecialchars(file_get_contents($src)));
break;
default:
header('HTTP/1.1 302 Found');
header('Location: ' . $src);exit;}
exit;}
# autocomplete
if(preg_match('/^\/([-_0-9a-zA-Z]{2,6})/', $_SERVER['REQUEST_URI'], $m))
if($matching = glob($m[1] . '*.txt') andcount($matching) == 1) {
header('HTTP/1.1 302 Found');
header('Location: /' . $matching[0]);
exit;}
# FIXME This only works on my server.
# Is there any way to trigger the local webservers native error page?
header('HTTP/1.1 404 Not Found');readfile('/home/www/status/404.html');