Hello, I see one potential problem with this detection in one special case.
This will only occur if you use Apache's feature PATH_INFO. There $current_page will be inaccurate as the scriptname might be /index.php but the URL could be /index.php/path/to/mypage or just /index/path/to/mypage - depending on Apache's configuration and link presentation. I mention this because I have used this extensively to work around having to rely on mod_rewrite. Richard -----Original Message----- From: John W. Holmes Sent: Monday, May 10, 2004, 2:21:36 AM > 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... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php