note 117307 deleted from reserved.variables.server by cmb

From: Date: Sun, 28 Jul 2019 08:02:05 +0000
Subject: note 117307 deleted from reserved.variables.server by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211709@lists.php.net to get a copy of this message
Note Submitter: joerg dot reinholz at fastix dot org ---- On a few of servers (e.g, Strato AG Germany, shared hosting) $_SERVER["DOCUMENT_ROOT"] follow symlinks (while so configured by admins) This is a problem while __DIR__ give the realpath. Try the error with this small script inside of DOCUMENT_ROOT: <?php header('Content-type: text/plain'); echo '__DIR__ : ', __DIR__ , "\n"; echo '$_SERVER["DOCUMENT_ROOT"] : ', $_SERVER["DOCUMENT_ROOT"] , "\n"; echo 'realpath($_SERVER["DOCUMENT_ROOT"]): ', realpath($_SERVER["DOCUMENT_ROOT"]), "\n"; ## file 'include_me.php' # Exit, wenn in document_root, weil dann Sicherheitsproblem auftreten kann: if (-1 < strpos(__DIR__, $_SERVER["DOCUMENT_ROOT"]) ) { trigger_error('Fatal: '. __FILE__ . ' darf nicht in oder unterhalb von DOCUMENT_ROOT (' . $_SERVER["DOCUMENT_ROOT"] . ') liegen!', E_USER_ERROR); exit; } ?> This will never trigger the error! Use better: <?php header('Content-type: text/plain'); echo '__DIR__ : ', __DIR__ , "\n"; echo '$_SERVER["DOCUMENT_ROOT"] : ', $_SERVER["DOCUMENT_ROOT"] , "\n"; echo 'realpath($_SERVER["DOCUMENT_ROOT"]): ', realpath($_SERVER["DOCUMENT_ROOT"]), "\n"; ## file 'include_me.php' # Exit, wenn in document_root, weil dann Sicherheitsproblem auftreten kann: if (-1 < strpos(__DIR__, $_SERVER["DOCUMENT_ROOT"]) ) { trigger_error('Fatal: '. __FILE__ . ' darf nicht in oder unterhalb von DOCUMENT_ROOT (' . $_SERVER["DOCUMENT_ROOT"] . ') liegen!', E_USER_ERROR); exit; } ?>

« previous php.notes (#211709) next »