note 117307 added to reserved.variables.server

From: Date: Tue, 19 May 2015 20:29:26 +0000
Subject: note 117307 added to reserved.variables.server
Groups: php.notes 
Request: Send a blank email to php-notes+get-202610@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 78.49.34.92 ---- Manual Page -- http://php.net/manual/en/reserved.variables.server.php Edit -- https://master.php.net/note/edit/117307 Del: integrated -- https://master.php.net/note/delete/117307/integrated Del: useless -- https://master.php.net/note/delete/117307/useless Del: bad code -- https://master.php.net/note/delete/117307/bad+code Del: spam -- https://master.php.net/note/delete/117307/spam Del: non-english -- https://master.php.net/note/delete/117307/non-english Del: in docs -- https://master.php.net/note/delete/117307/in+docs Del: other reasons-- https://master.php.net/note/delete/117307 Reject -- https://master.php.net/note/reject/117307 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202610) next »