需要能够从任何目录访问Common.php

需要能够从任何目录访问Common.php,php,Php,由于它是在www.example.com/page.php上运行的,而不是在更深层的目录下运行,因此您的论坛目录似乎位于/forum而不是/forum 所以改变 <div id="phpbbBox"><?php define('IN_PHPBB', true); $phpbb_root_path = './forum/'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'commo


由于它是在www.example.com/page.php上运行的,而不是在更深层的目录下运行,因此您的论坛目录似乎位于
/forum
而不是
/forum
所以改变

<div id="phpbbBox"><?php

define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx); 




// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();


if($user->data['is_registered'])
{

    echo "Hello " . "<a href=\"http://cgoava.com/forum/memberlist.php?mode=viewprofile&un=" . $user->data['username'] . "\">" . $user->data['username'] . "</a>"; //User is already logged in
    echo "<br /> You have " . "<a href=\"http://cgoava.com/forum/ucp.php?i=pm&folder=inbox\">" . $user->data['user_new_privmsg'] . " new PM!</a> ";
    echo "<br /> Last visit: " . $user->format_date($user->data['session_last_visit']);

}
else if(isset($_POST['login']))
{
    $username = request_var('username', '', true);
    $password = request_var('password', '', true);
    $autologin = (!empty($_POST['autologin'])) ? true : false;

    $result = $auth->login($username, $password, $autologin);

    if ($result['status'] == LOGIN_SUCCESS)
    {
        //User was successfully logged into phpBB


        // append/replace SID
        $redirect = reapply_sid($_SERVER['PHP_SELF']);
    meta_refresh(0, $redirect);
    echo "<script type=\"text/javascript\">
    location.reload();
    </script>";
    }
    else
    {
        echo 'Bad Login ' . $username; //User's login failed
    }
}
else
{
    echo '<form method="POST" action="">
        <input type="text" name="username" size="10">
        <input type="password" name="password" size="10"><br />
         Remember Me?: <input type="checkbox" name="autologin">
        <input type="submit" value="Submit" name="login">
        </form>';
}
?></div>


(./是当前目录,因此它正在www.example.com/ex/forum/common.php中查找common.php)

在这种情况下,不能使用相对路径。如果将
$phpbb_root_path
设置为绝对路径,则从该变量构建路径将正常工作

尝试:


没有什么比从文档根目录向下运行更好的了<代码>$phpbb_root_path=$_SERVER['DOCUMENT_root']。'path/to/forum/'非常感谢您,先生!
$phpbb_root_path = './forum/';
$phpbb_root_path = '/forum/';
$phpbb_root_path = $_SERVER['DOCUMENT_ROOT'] . '/folder/to/forum/';