Jump to content


Photo

"include" not setting SERVER variables correctly


  • Please log in to reply
4 replies to this topic

#1 nfr

nfr
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 27 May 2006 - 04:59 PM


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.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 May 2006 - 09:07 PM

How are you coding the include statement?

Ken

#3 nfr

nfr
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 28 May 2006 - 12:16 PM


It is included as follows:

<?php include("http://www.servernam.../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.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 May 2006 - 01:39 PM

If the file is local, you do not want to use the full URL. That gets rid of your first attempt.

Your second attempt:
<?php include("/includes/myinclude.php"); ?>
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
<?php include("includes/myinclude.php"); ?>
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


#5 nfr

nfr
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 28 May 2006 - 02:21 PM


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.co.../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.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users