Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Staggan - toukokuu 15, 2014, 09:52:19 AP

Otsikko: Losing session variable in forums
Kirjoitti: Staggan - toukokuu 15, 2014, 09:52:19 AP
Hello

We are using the smf 2 api to integrate SMF into our site, which is working well, but we have a problem with a session variable.

Once we have successfully logged a user in we set the following session var:



$_SESSION["loggedIn"] = 1;



And use that to decide if we show the user as logged in or not.

This works fine on every single page except the forums page. Our header / menu loads fine but it seems that the session variable is somehow lost. However, if we go back to the site home page, our session variable is still working as it shows us still logged in.

Any ideas? Does the forum do something to prevent or reset my session variable?

Any help would be greatly appreciated

Thanks

Otsikko: Re: Losing session variable in forums
Kirjoitti: Staggan - toukokuu 15, 2014, 10:31:38 AP
I have tried not starting a new session by doing this in /forums/Sources/load.php



if(session_status() === PHP_SESSION_NONE) {
session_start();
}



But it makes no difference..

Otsikko: Re: Losing session variable in forums
Kirjoitti: margarett - toukokuu 15, 2014, 12:19:42 IP
I'm not sure how the API works, but with SSI you can just use $context['is_logged'] which is set by SMF upon successful login. I assume something similar exists with the API.

Or aren't you using SMF's login system?
Otsikko: Re: Losing session variable in forums
Kirjoitti: Staggan - toukokuu 15, 2014, 12:42:24 IP
Hello

No, we have our own login system.

We were using PHPBB, but changed.... just having a few issues...

Otsikko: Re: Losing session variable in forums
Kirjoitti: Arantor - toukokuu 15, 2014, 12:44:54 IP
Of course it will be lost. SMF has its own session handler. On the downside, this means it's usually far easier to not roll your own and extend SMF's, but on the upside you get something that's been around for a decade and proven against things like session fixation bugs which seem to crop up in NIH environments.

This is why I said to you before about doing it SMF's way.
Otsikko: Re: Losing session variable in forums
Kirjoitti: Staggan - toukokuu 15, 2014, 01:24:09 IP
Our login system is based around our online game, and has been around quite some time, and therefore we need SMF to integrate into our system in the same way PHPBB did....

I can register users and log users in without issue, all good, but when it comes to logging users out and setting the logged in status at the top of the header page, it is a pain.

I'll spend a little more time looking at it..


Thanks