Jump to content

Archived

This topic is now archived and is closed to further replies.

nfr

"include" not setting SERVER variables correctly

Recommended Posts


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.

Share this post


Link to post
Share on other sites
How are you coding the include statement?

Ken

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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"); ?>
and
2.) <?php include("myinclude.php"); ?>
and
3.) <?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.


Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.