Forum Session variable problem

Submitted by Anonymous on Fri, 06/01/2012 - 13:14
Written by
Dreggs99

Hi,

I am new to useBB and seem to be having some problems implementing session variables within the forum.

I am trying to create a new session variable when the user logs into the system. Something like:

session_start();
$_SESSION['user'] = "TEST";

However when i try to access this session in a directory outside of the forum it does not pick it up:

if(!isset($_SESSION['user']))
{
echo "NOT LOGGED IN";
}
else
{
echo "LOGGED IN";
}

The code above always echo's 'NOT LOGGED IN'

Could anyone give me any pointers on what I'm doing wrong?

Thanks

Ensure UseBB's cookie path setting is set to "/". You must also only use the variable when common.php has been loaded, and preferrably not use session_start() yourself.

Hi,

Thanks for your reply.

I have tried what you have mentioned but with no success. I presume setting the cookie path to '/' makes it apply to the whole domain?

Is there anything else you can suggest?

Thanks

I think you are not reopening the session created by UseBB. Try experimenting with session_set_cookie_params() to get the exact same settings as set by UseBB (domain, path, etc).

Hi again,

Forgive but I'm new to PHP. I tried this code but doesn't seem to work:

session_set_cookie_params( time() + 600, '/', 'example.co.uk', false, false);
$_SESSION['TEST'] = "TEST";

Still can't pick up sessions defined within UseBB. Is this the right way of using this?

Note "example.co.uk" will probably only work for that exact host, not www.example.co.uk. Therefore you would use ".example.co.uk".

I can't really see where exactly you are setting the session variable. If you do this in UseBB I would do this at the end of sources/common.php, and read the variable in your own system. In UseBB itself you then do NOT call session_*() yourself.

If it doesn't work the code or settings might still be wrong.

Thanks very much for your help, I have it working now

:mrgreen: