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?

Link to comment
Share on other sites

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');
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.