[SOLVED] includes and variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
LegoBoy
Forum Newbie
Posts: 9
Joined: Fri Jul 16, 2004 4:02 pm

[SOLVED] includes and variables

Post 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"?
Last edited by LegoBoy on Tue Aug 03, 2004 7:51 pm, edited 1 time in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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.
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

Use something like this:

Code: Select all

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