note 112425 added to reserved.variables.server
| From: | pomat at live dot it | Date: | Sat, 15 Jun 2013 14:12:10 +0000 |
| Subject: | note 112425 added to reserved.variables.server | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195230@lists.php.net to get a copy of this message | ||
$_SERVER['DOCUMENT_ROOT'] may contain backslashes on windows systems, and of course it may
or may not have a trailing slash (backslash).
I saw the following as an example of the proper way we're supposed to deal with this issue:
<?php
include(dirname($_SERVER['DOCUMENT_ROOT']) . DIRECTORY_SEPARATOR . 'file.php');
?>
Ok, the latter may be used to access a file inside the parent directory of the document root, but
actually does not properly address the issue.
In the end, don't warry about. It should be safe to use forward slashes and append a trailing
slash in all cases.
Let's say we have this:
<?php
$path = 'subdir/file.php';
$result = $_SERVER['DOCUMENT_ROOT'] . '/' . $path;
?>
On linux $result might be something like
1) "/var/www/subdir/file.php"
2) "/var/www//subdir/file.php"
String 2 is parsed the same as string 1 (have a try with command 'cd').
On windows $result might be something like
1) "C:/apache/htdocs/subdir/file.php"
2) "C:/apache/htdocs//subdir/file.php"
3) "C:\apache\htdocs/subdir/file.php"
4) "C:\apache\htdocs\/subdir/file.php"
All those strings are parsed as "C:\apache\htdocs\subdir\file.php" (have a try with
'cd').
----
Server IP: 69.147.83.199
Probable Submitter: 79.51.29.3
----
Manual Page -- http://php.net/manual/en/reserved.variables.server.php
Edit -- https://master.php.net/note/edit/112425
Del: integrated -- https://master.php.net/note/delete/112425/integrated
Del: useless -- https://master.php.net/note/delete/112425/useless
Del: bad code -- https://master.php.net/note/delete/112425/bad+code
Del: spam -- https://master.php.net/note/delete/112425/spam
Del: non-english -- https://master.php.net/note/delete/112425/non-english
Del: in docs -- https://master.php.net/note/delete/112425/in+docs
Del: other reasons-- https://master.php.net/note/delete/112425
Reject -- https://master.php.net/note/reject/112425
Search -- https://master.php.net/manage/user-notes.php