Root Path

Discussion in 'PHP' started by johneva, Mar 1, 2011.

  1. #1
    Hi

    I am trying to use this bit of code to make a login for a different area of a site which uses the same login as the PHPBB login.

    http://www.phpbb.com/kb/article/phpbb3-sessions-integration/

    I got it to work on files in the root of the site, but want it to work on files in a folder named control-panel for example.

    The forum is in a folder named forum so had to add that into the code already for it to work but need some help on how to adjust this bit.

    
    <?php
    define('IN_PHPBB', true);
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? 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();
    ?>
    
    <h1>Blah Blah Blah</h1>
    
    <?php
    if ($user->data['user_id'] == ANONYMOUS)
    {
       echo '<p>Please login!<p>';
    }
    
    else
    {
       echo '<p>Thanks for logging in, ' . $user->data['username_clean'] . '</p>';
    }
    ?>
    
    PHP:
    Comes up with the error carnt find file and the path has the control panel folder in it due to the way the php finds its file path.
     
    johneva, Mar 1, 2011 IP
  2. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    try this code

    
    
    <?php
    define('IN_PHPBB', true);
    define('ROOT_PATH', "../forum"); //this is the folder where your phpBB3 installation is at...
    
    if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {
        exit();
    }
    
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
     
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();
    
    ?>
    
    <h1>Blah Blah Blah</h1>
    
    <?php
    if ($user->data['user_id'] == ANONYMOUS)
    {
       echo '<p>Please login!<p>';
    }
    
    else
    {
       echo '<p>Thanks for logging in, ' . $user->data['username_clean'] . '</p>';
    }
    ?>
    
    PHP:
     
    IAreOwn, Mar 1, 2011 IP
    johneva likes this.
  3. johneva

    johneva Well-Known Member

    Messages:
    1,480
    Likes Received:
    46
    Best Answers:
    1
    Trophy Points:
    170
    #3
    Ah yeah that works, thats great cheers for your help.
     
    johneva, Mar 1, 2011 IP