Page 1 of 1

[SOLVED] includes and variables

Posted: Tue Aug 03, 2004 3:09 pm
by LegoBoy
I have a vars.php in the root directory of my web site. This file contains variables that I need to use in nearly every page. The problem is that when I include it the variables are not passed to the file that called it. EG

Code: Select all

<?php
  // include the variables
  include( "http://$_SERVER[HTTP_HOST]/vars.php" );
  // display the variables
  // this is what doesn't work
  echo "$blogRoot<br>";
?>
I tested to see if the file was being included, and yes it is.

How can I include a file in the root directory of my web site and use it's variables without somthing like "../../vars.php"?

Posted: Tue Aug 03, 2004 3:28 pm
by d3ad1ysp0rk
I do not believe you can. This is for security issues of course..
The only thing I can think of is having a function tell you how many levels in you are (ie. http://domain.com/file.php is 0, http://host.com/users/username/ is 2) and then use a for loop at add ../ for each folder.

Posted: Sun Aug 15, 2004 4:43 pm
by tomfra
Use something like this:

Code: Select all

include("{$_SERVER['DOCUMENT_ROOT']}/vars.php");
Tomas