note 25712 deleted from function.include by sniper

From: Date: Wed, 29 Jan 2003 04:14:56 +0000
Subject: note 25712 deleted from function.include by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-42993@lists.php.net to get a copy of this message
I develop on a local Apache server, but my host is IIS. Imagine my amazement when I found that IIS doesn't set $DOCUMENT_ROOT! I wanted to use absolute includes (none of this "../phpfile.php" nonsense, which can break if I move the page). After looking around, I found out that IIS does set PATH_TRANSLATED and PATH_INFO. Examples: PATH_TRANSLATED = c:\\root\\subdirectory\\phpfile.php PATH_INFO = /subdirectory/phpfile.php Here's what I came up with: // if $DOCUMENT_ROOT does not exist, build one from scratch out of PATH_TRANSLATED and PATH_INFO. $include_path = (!$_SERVER['DOCUMENT_ROOT']) ? str_replace($_SERVER["PATH_INFO"], "", str_replace("\\\\", "/", $_SERVER["PATH_TRANSLATED"])) : $_SERVER['DOCUMENT_ROOT']; I str_replace the \\ in PATH_TRANSLATED to /, then cut PATH_INFO off of it. This returns what would normally be in $DOCUMENT_ROOT. Put THIS in the beginning of every file, then write your includes as include($include_path . "/phpfile.php"); Then you'll never have to rewrite it again, even if you shuffle your directories.

« previous php.notes (#42993) next »