ivordurham Posted December 17, 2007 Share Posted December 17, 2007 I need some help to understand why $_SERVER['HTTP_HOST'] is defined in one situation but not in another very similar one. Consider the following very simple PHP script which dumps the $_SERVER array: <?php print_r($_SERVER); ?> I have this script as the contents of two separate files named "xxxxtest.php" and "xxxxxtest.php" (four x's and then five x's) on a web site hosted at GoDaddy. Now retrieve the output of this script via file_get_contents. Specifically I am retrieving the following two URLs and getting an unexpected difference in the output: http://www.calyscats.org/admin/xxxxtest.php and http://www.calyscats.org/admin/xxxxxtest.php The specific problem is that the content retrieved via the four-x script shows $_SERVER['HTTP_HOST'] defined correctly ('www.calyscats.org') while the five-x script shows that $_SERVER['HTTP_HOST'] is UNDEFINED! (i.e. it is not included in the $_SERVER dump). In fact HTTP_HOST is undefined when the script filename is even longer and works correctly for shorter filenames. It seems like an "8.3" filename limit is playing a role somewhere. If I retrieve the two URLs using a method other than file_get_contents (e.g. via the "wget" program or open them in a web browser), HTTP_HOST is defined as expected. If I create an equivalent Perl script on the same web site to dump the %ENV variable, HTTP_HOST is defined regardless of the length of the filename, so the problem seems to be PHP-related. If I put the same scripts on a web site at another ISP, HTTP_HOST is defined properly in both cases. So only when I retrieve the output of the five-x PHP script via file_get_contents from the site hosted at GoDaddy is HTTP_HOST undefined. Why? I have tried this with both PHP 4.4.4 and 5.2.4 on the client side. GoDaddy is running PHP 4.3.11 under Apache 1.3 on Red Hat Linux. Any idea about what in the Apache/PHP 4.3.11 configuration at GoDaddy could account for HTTP_HOST being defined when file_get_contents retrieves the script output and the script name is xxxxtest.php and undefined when it is one character longer: xxxxxtest.php? Needless to say, this is not just an academic exercise; a real script is trying to use $_SERVER['HTTP_HOST'] to compose a URL to an image that is included in a data file that is being retrieved via file_get_contents by another site, so the URL ends up without a host component and is consequently broken. In this case I can work around the problem by using SERVER_NAME, but that is not true across all installations of the software. Thanks in advance any insight into what is going on. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.