page: save document root for includes during shutdown
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Sep 2017 15:11:46 +0000 (17:11 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 18 Sep 2017 18:21:28 +0000 (20:21 +0200)
Current directory is unavailable in fatal error handler.

page.inc.php
page.php

index 654f37fa7ebeee2a412b2348fc3bab61d1ac4d88..c0282eea341fcec090015953950f7c601c504c8f 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 $body = ob_get_clean();
 
-include_once './head.inc.php';
+include_once DOCROOT.'head.inc.php';
 
 print "<header>\n";
 ob_start();
-include './menu.html';
+include DOCROOT.'menu.html';
 $nav = ob_get_clean();
 $nav = preg_replace_callback('{<a href="([^"]+)">(.*?)</a>}', function ($m) {
        $request = $_SERVER['REQUEST_URI'];
@@ -24,10 +24,9 @@ print "</header>\n\n";
 
 print $body;
 
-$footinc = realpath('footer.html'); # cwd lost during shutdown
 register_shutdown_function(function () {
        print '<footer>';
-       @include $GLOBALS['footinc'];
+       @include DOCROOT.'footer.html';
        print "</footer>\n";
 
        global $User;
index dc7f0128a609ef0b0178b9318faff1e62d7f693f..02886a77a04d88faac98d30f7b7570a1a23ba375 100644 (file)
--- a/page.php
+++ b/page.php
@@ -16,12 +16,14 @@ function getoutput($blocks = [])
 
 # custom error handling
 
+define('DOCROOT', getcwd().'/');
+
 function fail($error)
 {
        http_response_code(500);
        include_once 'page.inc.php';
        ob_start();
-       require_once './500.html';
+       require_once DOCROOT.'500.html';
        print getoutput(['debug' => $error]);
 }