Valutazione attuale: 1 / 5

Stella attivaStella inattivaStella inattivaStella inattivaStella inattiva
 

GLOBAL VAR DOCUMENT ROOT IN A WINDOWS HOST

If your hosting has php under a windows host you will have a problem with $_SERVER['DOCUMENT_ROOT'] : it will return blank.
Include this code where you need to use the $_SERVER['DOCUMENT_ROOT'] as usual.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
<REMOVE_ME?php
if( ! isset( $_SERVER['DOCUMENT_ROOT'] ) ) {
 if( isset($_SERVER['SCRIPT_FILENAME'] ) ) {
 $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
 };
};
if( ! isset($_SERVER['DOCUMENT_ROOT']) {
 if (isset($_SERVER['PATH_TRANSLATED'] ) ) {
 $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
 };
};
// And now you can use document_root as usual<br />echo "DOCUMENT_ROOT : ".$_SERVER['DOCUMENT_ROOT']."";
?REMOVE_ME>;

 

DISQUS - Leave your comments here