سؤال

I am currently making a website that is fused with a phpBB forum. Following the official solution to phpBB3 Sessions Integration I have used the following code to include relevant files from my phpBB install:

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'forums/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

My forum folder is (root path)/forums/, so this works perfectly as long as the executing script is in the root folder of the domain. However, if I try to include this code from another folder, it throws the following error:

[phpBB Debug] PHP Warning: in file /home/unrealsp/public_html/includes/phpbb.php on line 5: include(forums/common.php) [function.include]: failed to open stream: No such file or directory [phpBB Debug] PHP Warning: in file /home/unrealsp/public_html/includes/phpbb.php on line 5: include(forums/common.php) [function.include]: failed to open stream: No such file or directory [phpBB Debug] PHP Warning: in file /home/unrealsp/public_html/includes/phpbb.php on line 5: include() [function.include]: Failed opening 'forums/common.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') [phpBB Debug] PHP Warning: in file /home/unrealsp/public_html/includes/phpbb.php on line 6: include(forums/includes/functions_display.php) [function.include]: failed to open stream: No such file or directory [phpBB Debug] PHP Warning: in file /home/unrealsp/public_html/includes/phpbb.php on line 6: include(forums/includes/functions_display.php) [function.include]: failed to open stream: No such file or directory [phpBB Debug] PHP Warning: in file /home/unrealsp/public_html/includes/phpbb.php on line 6: include() [function.include]: Failed opening 'forums/includes/functions_display.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')

My solution attempt was as follows:

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'forums/';

to

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '/forums/';

but that just broke it when run from the domain root, too, rather than fixing it, which is also something I don't understand.

How to include my phpBB code reliably from any location on the server?

Addendum: I am currently using a temporary URL for my webspace, which is made up of an URL with a user folder, like http://XXX.XXX.XXX.XXX/~user/. However, changing the variable to '/~user/forums/' didn't work, either.

هل كانت مفيدة؟

المحلول

I had the same problem with my site which I solved by getting the URL of the page and exploding it at every slash. I then used count() on the exploded array which tells me how deep into the directory structure the page is and used that number to add the required number of ../ 'up a directory' to the root path.

نصائح أخرى

Since I found this question Googling for the same issue, I'd like to point out that $phpbb_root_path as nothing to do with the URL! It's related to the filesystem path to the phpBB installation directory, relative to the current executing PHP script (intended as "PHP file"). In a very basic scenario you can ignore the difference, but when mod_rewrites are in it's important to work it in the right way.

Since I needed to fix this issue quickly, I punched through with an horror such as this (SiteDir is a constant defined as the path to my site root, i.e. /user/site/):

    $dai=$_SERVER["SCRIPT_FILENAME"];
    $dai2=str_ireplace("\\", "/", SiteDir);
    $dai=str_ireplace($dai2, "", $dai);

    $depth=substr_count($dai, "/");
    $dai="";

    for($i=0; $i<$depth; $i++)
        { $dai="../"; }

    $dai.="forum/";

    $phpbb_root_path=$dai;

Also keep an eye on this thread I opened on the phpBB support forum for more "official" ways to make it work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top