Re: How can I replace $_SERVER["DOCUMENT_ROOT"] in PHP 7.0?

From: Date: Tue, 14 Sep 2021 22:42:30 +0000
Subject: Re: How can I replace $_SERVER["DOCUMENT_ROOT"] in PHP 7.0?
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-327688@lists.php.net to get a copy of this message
On Tue, 14 Sep 2021 14:48:57 +0100, AllenJB <php.lists@allenjb.me.uk> wrote: >To account for symlinks (which allow you to pretend a file or directory >is in another place on the filesystem), run each path through realpath() >(I believe __DIR__ is already resolved for its "real path", but it >doesn't hurt to run it through again in this case to be sure) I used this php file put in a subdir below document root: <?php $rootdir= substr(__DIR__, 0, strpos( __DIR__, 'htdocs')) . 'htdocs'; echo "Root dir: " . $rootdir . "<br>"; echo "Real root path: " . realpath($rootdir) . "<br>"; $docroot=$_SERVER["DOCUMENT_ROOT"]; echo "Document root: " . $docroot . "<br>"; echo "Real document root: " . realpath($docroot) . "<br>"; include ($rootdir . '/php/logindata.php'); echo "Mail sender using Real root path: " . $mailsender ; ?> The printed output whan I call this php file with FireFox: Root dir: /data/25/2/158/91/2484743/user/2721122/htdocs Real root path: /data/25/2/158/91/2484743/user/2721122/htdocs Document root: /usr/services/vux/apache/htdocs Real document root: /usr/services/vux/apache/htdocs Mail sender using Real root path: donald@duck.com Notice that the two paths grabbed by __DIR__ and $_SERVER["DOCUMENT_ROOT"] are clearly different and using the latter in the include will make the $mailsender variable empty. -- Bo Berglund Developer in Sweden

« previous php.general (#327688) next »