Page 1 of 1

Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 6:19 am
by Saldash
Hi,

I have search here and found a topic about using PHPbb sessions on an existing site:
this link - http://www.phpbb.com/kb/article/phpbb3- ... tegration/

I followed the tutorial however I get an error "Call to a member function on a non-object",
It points to this line: $user->session_begin();

Here is the code I have used:

Code: Select all

<?php
Include("site_settings.php");
define('IN_PHPBB', true);
$phpbb_root_path = (defined('http://forum.world-recoded.co.uk')) ? http://forum.world-recoded.co.uk : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
The use of Include("site_settings.php"); is that I wish to be able to disable this feature using an if statement on a value in this settings file later on..

The code I am using to check a logged in user is this:
(Modified to check whether or not it is disabled using $settings['EnableLogin'] )

Code: Select all

<?PHP
if ( $settings['EnableLogin'] == TRUE ) {
if ($user->data['user_id'] == ANONYMOUS)
{
   echo 'Please login!';
}
else
{
   echo 'Thanks for logging in, ' . $user->data['username_clean'];
}	
} else {
	Echo "Login Closed";
}
?>
Whats wrong with my code? Because I dont really understand PHP all that well..
This is a link to my sandbox testing page - You can see the error.. Here
Cheers,
Saldash

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 8:55 am
by Erik Frèrejean
You are doing some strage thing around here. Can you try the following?

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_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();

// Site settings here:
Include("site_settings.php");
?>

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:04 am
by Saldash
Here is what i have done so far.. I thought this wouuld work but it hasn't..

I took both code samples AS IS from the tutorial posted, and saved to a single file called session_extension.php and then upload this to my forum directory..

If I run this file directly.. i get the correct result!
But my intension with that was to be able to simply use this from all of my pages:

Code: Select all

<?PHP
Include("site_settings.php"); //Site settings defines "$settings['EnableLogin'] == TRUE"
?>
//PAGE CONTENTS HERE
<?PHP
If ( $settings['EnableLogin'] == TRUE );
    Include("forum/session_extension.php");
else
    Echo "Login Closed";
?>
But when I do that, and call the extender from outside the forums directory, it returns an error..
Is there a way to specificly point the script to a different directory and not have to have to either move my forum or site pages?
The file "session_extension.php" contains the following:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
if ($user->data['user_id'] == ANONYMOUS)
{
   echo 'Please login!';
}
else
{
   echo 'Logged in as: ' . $user->data['username']; echo '.' ;
}
?>

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:14 am
by Erik Frèrejean
Okay, I assumed that the session integration was in the same file. The trick is that:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_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(); 
Must be the very first thing that gets executed. So move that block to the top of your index.php file (or whatever file gets called first when entering a page).

Also make sure that you don't use a $user variable anywhere in your own system as this will cause conflicts.

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:23 am
by Saldash
Thanks for your replies,

I get what your saying, I have updated my last post so its a bit more accurate to what im after..
The settings file needs to come first as I need to be able to disable login detection on my website pages
(sounds odd yeah, but thats what I need, the site settings file will only set values to the &settings[] array.
so there should be no conflicts between the two scripts at all.

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:28 am
by Erik Frèrejean
Could you dump the $user object and post its content? To do this place before:

Code: Select all

// Start session management 
the following code:

Code: Select all

echo'<pre>';
var_dump($user);
exit; 

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:34 am
by Saldash
The code you have posted will only work if its run from the same directory as the forum.
My issues is that the forum and the website are not in the same directory folder.

my forum is here : http://forum.world-recoded.co.uk/
The site folder for the forum is here: http://www.world-recoded.co.uk/forum/

the page where i want to extend the session to is:
http://www.world-recoded.co.uk/pages.php

/Index.php <- webpage where I want to included " /forum/session_extension.php " if settings file allows login detect.
/forum/Index.php <- where only the forum is stored
/forum/session_extension.php <- the file im including in my web pages

Hope that helps clear things up

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:39 am
by Saldash
Dump info for user:
object(user)(24) {
["cookie_data"]=>
array(0) {
}
["page"]=>
array(0) {
}
["data"]=>
array(0) {
}
["browser"]=>
string(0) ""
["forwarded_for"]=>
string(0) ""
["host"]=>
string(0) ""
["session_id"]=>
string(0) ""
["ip"]=>
string(0) ""
["load"]=>
int(0)
["time_now"]=>
int(0)
["update_session_page"]=>
bool(true)
["lang"]=>
array(0) {
}
["help"]=>
array(0) {
}
["theme"]=>
array(0) {
}
["date_format"]=>
NULL
["timezone"]=>
NULL
["dst"]=>
NULL
["lang_name"]=>
bool(false)
["lang_id"]=>
bool(false)
["lang_path"]=>
string(11) "./language/"
["img_lang"]=>
NULL
["img_array"]=>
array(0) {
}
["keyoptions"]=>
array(10) {
["viewimg"]=>
int(0)
["viewflash"]=>
int(1)
["viewsmilies"]=>
int(2)
["viewsigs"]=>
int(3)
["viewavatars"]=>
int(4)
["viewcensors"]=>
int(5)
["attachsig"]=>
int(6)
["bbcode"]=>
int(8)
["smilies"]=>
int(9)
["popuppm"]=>
int(10)
}
["keyvalues"]=>
array(0) {
}
}

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:42 am
by Erik Frèrejean
Okay, I'm a bit confused regarding your file structure so lets see if I have this correct. It look something like:

Code: Select all

root
  |- index.php
  |- forum
        |- index.php
  |- session_intergration.php

Re: Extending PHPbb session to existing site

Posted: Wed Dec 31, 2008 9:55 am
by Saldash

Code: Select all

root
  |- SiteIndex.php
  |- site_settings.php
  |- forum
       |- Index.php
       |- session_extension.php
  |- secondpage.php
I want to be able to query a TRUE / FALSE setting and include the session_extenstion.php only if true..
If open the session_extenstion.php directly in my browser it works fine..
But I get an error if i try to include it in the SiteIndex.php file