Jump to content

[SOLVED] Question about paths for multiple includes


bpops

Recommended Posts

I have a very strange problem. I have a directory structure such as this:

 

/web/

/web/forum/

/web/test/

 

Under '/web/' I have a php file (top.php) that I include in every page that signs people into the forum automatically. To access the forum, though, there's an include in top.php. i.e.

 

<?php
// top.php

include('../forum/forum.php');
?>

 

When I include top.php in a file under '/web' it goes like this:

 

<?php
// index.php

include('top.php');
?>

 

This all works fine. The problem arises when I have a file under '/web/test/.' I include top.php via

 

<?php
// /web/test/index.php

include('../top.php');
?>

 

It grabs top.php just fine, but since IN top.php, the path to the forums is '../forum/' and not '../../forum/', I get an error. Is there an easy way to fix this still using my single top.php file? Are there any root directory commands or something?

well...then decide what you want your base to be. I'm going to make a decision and set the 'include base' to be the root of all this stuff.

 

<?php
// /web/top.php
$include_base = dirname(dirname(__FILE__));
include($include_base.'/forum/forum.php');
?>

 

<?php
// /web/index.php
include('top.php');
?>

 

<?php
// /web/test/index.php
include('../top.php');
?>

Archived

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

×
×
  • Create New...

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.