Re: Does this "directory detection" script work for you?

From: Date: Mon, 10 May 2004 05:50:08 +0000
Subject: Re: Does this "directory detection" script work for you?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185776@lists.php.net to get a copy of this message
Hi, I use the following class to get Path information: http://ircphp.com/users/imho/?file=Path.php Let me know if this is helpful at all "John W. Holmes" <holmes072000@charter.net> wrote in message news:409ECB10.6020207@charter.net... > Hello. I'm relying on the following code so that a script can > automatically detect where it's installed and create paths and URLs from > the information. This way absolute paths and URLs are always used. > > I've had a couple people report that the script wasn't finding the paths > correctly, though, so I'm asking if people could test this out on their > server and see if it detects the paths or not. > > <?php > //Install path (path to survey.class.php) > $path = dirname($_SERVER['PATH_TRANSLATED']); > > //Determine protocol of web pages > if(isset($_SERVER['HTTPS']) && > strcasecmp($_SERVER['HTTPS'],'ON') == 0) > { $protocol = 'https://'; } > else > { $protocol = 'http://'; } > > //HTML address of this program > $dir_name = dirname($_SERVER['SCRIPT_NAME']); > if($dir_name == '\\') > { $dir_name = ''; } > > $html = $protocol . $_SERVER['SERVER_NAME'] . $dir_name; > > //Determine web address of current page > $current_page = $protocol . $_SERVER['SERVER_NAME'] . > $_SERVER['SCRIPT_NAME']; > > echo "Path to script: $path<br />"; > echo "URL to script directory: $html<br />"; > echo "URL to current script: $current_page"; > ?> > > It should print out the file system path to where the script was placed > as well as a URL to the directory it was placed and a URL to the file > itself. > > I've never had an issue with it personally and I've tested it on Apache > and IIS on both Windows and Linux. So maybe it's some obscure CGI or OS > configuration where this isn't working? I just need to know so I can > plan accordingly. > > The only two substitutions that can be made (that I know of) are: > > $_SERVER['SCRIPT_NAME'] => $_SERVER['PHP_SELF'] > and > $_SERVER['PATH_TRANSLATED'] => $_SERVER['SCRIPT_FILENAME'] > > If it doesn't work for you, does it work if you do one of those > substitutions? > > Also, this will test if the script is in subdirectories or not, also, so > testing it within one and seeing if that works, too, is appreciated. > > Thanks for any help and time you're willing to provide. > > -- > ---John Holmes... > > Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ > > php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#185776) next »