nfr Posted May 27, 2006 Share Posted May 27, 2006 Hello -If I run the following PHP the output is OK:<?php$remote_addr = $_SERVER['REMOTE_ADDR'];$http_user_agent = $_SERVER['HTTP_USER_AGENT'];echo "REMOTE_ADDR: $remote_addr";echo "HTTP_USER_AGENT: $http_user_agent";print_r($GLOBALS);?>However, if I run this as an "include", only the IP address of the UNIX server hosting Apache is output.Also, I seem to have lost the following:$_SERVER['HTTP_REFERER'];This was outputting correctly but now outputs nothing.Why is this?Regards,Neil. Quote Link to comment https://forums.phpfreaks.com/topic/10590-include-not-setting-server-variables-correctly/ Share on other sites More sharing options...
kenrbnsn Posted May 27, 2006 Share Posted May 27, 2006 How are you coding the include statement?Ken Quote Link to comment https://forums.phpfreaks.com/topic/10590-include-not-setting-server-variables-correctly/#findComment-39542 Share on other sites More sharing options...
nfr Posted May 28, 2006 Author Share Posted May 28, 2006 It is included as follows:<?php include("http://www.servername.com/includes/myinclude.php"); ?>This output what it should have done.I also tried:<?php include("/includes/myinclude.php"); ?>This returned nothing.But what is also wierd is that I used to get a value for $_SERVER['HTTP_REFERER'] but I do not any longer.Any clues?Cheers,Neil. Quote Link to comment https://forums.phpfreaks.com/topic/10590-include-not-setting-server-variables-correctly/#findComment-39682 Share on other sites More sharing options...
kenrbnsn Posted May 28, 2006 Share Posted May 28, 2006 If the file is local, you do not want to use the full URL. That gets rid of your first attempt.Your second attempt:[code]<?php include("/includes/myinclude.php"); ?>[/code]is telling PHP to look for the file in the directory "includes" directly under the root directory of your machine. This is probably not the correct place to look.If you do[code]<?php include("includes/myinclude.php"); ?>[/code]instead, it will tell PHP to look for the "includes" in the same directory as the script is located. This is probably what you want.Ken Quote Link to comment https://forums.phpfreaks.com/topic/10590-include-not-setting-server-variables-correctly/#findComment-39699 Share on other sites More sharing options...
nfr Posted May 28, 2006 Author Share Posted May 28, 2006 Hi -I've tried different permutations of your suggestion with the following code:<?php$remote_addr = $_SERVER['REMOTE_ADDR'];$http_referer = $_SERVER['HTTP_REFERER'];$http_user_agent = $_SERVER['HTTP_USER_AGENT'];echo "REMOTE_ADDR: $remote_addr";echo "HTTP_REFERER: $http_referer";echo "HTTP_USER_AGENT: $http_user_agent";print_r($GLOBALS);echo "<br><br><br><br><br>";echo "HTTP_SERVER_VARS";echo "$HTTP_SERVER_VARS";echo "<br><br><br><br><br>";?>1.) <?php include("http://www.mysite.com/myinclude.php"); ?>and2.) <?php include("myinclude.php"); ?>and3.) <?php include("/path/from/root/to/myinclude.php"); ?>The first instance of HTTP_REFERER is OK. In the include only the 1.) (full URL) echoes out anything at all. 2.) and 3.) provide no output. However, 1.) does not list the REMOTE_ADDR correctly and does not output anything for the HTTP_REFERER. Instead of it being the correc referrer IP address, it is the IP address of the machine serving www.mysite.com.Any ideas?Regards,Neil. Quote Link to comment https://forums.phpfreaks.com/topic/10590-include-not-setting-server-variables-correctly/#findComment-39706 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.