News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Sessions not transfering from website to forum

Started by CoffeeAddict, May 26, 2012, 03:19:51 PM

Previous topic - Next topic

CoffeeAddict

I've been trying to get the sessions from by website to transfer to the forum header and haven't had any success.

I've integrated my own header file so the look of the forum is the same as the website, and this is where I'd like the sessions to transfer. So that when a user goes from the site where they are logged in, to the forums, they will still be logged in at the top as usual.

I have this code in all my files

<?php
session_start();
require_once("/home/bestinsh/inc/classes.php");
require_once("/home/bestinsh/inc/config.php");
require_once("/home/bestinsh/inc/functions.php");
dbConnect(db_host, db_user, db_password, db_name);
if ($_SESSION["user_id"])
$user->updateLogIn($_SESSION["user_id"]);
?>


I am NOT expecting the actual forums to recognize the user as logged in, JUST the header that's wrapped around the forums.

I suspect it has something to do with the settings for the forum that's keeping this from happening. If I create a test file in the forum directory the sessions work fine, it's just when I visit the actual forum that they don't. Help please?


CoffeeAddict

Anyone? I'm still stuck on this, there has to be a way for the cookies/sessions/whatever to transfer to the header from the website, but let the actual forum cookies stay the same.


Arantor

You will need to include SMF's SSI.php file and do so before all your other stuff since that handles sessions (note that sessions are stored in the database, which is not the normal way of things)
Holder of controversial views, all of which my own.


CoffeeAddict

I included that file in the header before the other stuff and nothing seems to have changed. I don't think I'm doing this correctly.

Arantor

You didn't mention that before.

You're also starting another session and going through a lot of database stuff that SMF already does itself anyway.
Holder of controversial views, all of which my own.


CoffeeAddict

Oh no, I didn't do it before, I just added that include file after your suggestion.

So there's no way to make this work? I just want the header in the theme design to display the user as logged into the site, I'm not trying to change the actual forum sessions.

Arantor

That's the thing, the forum header is built into SMF and requires SMF's setup to have run in the first place... since it relies on a bunch of SMF variables to have been defined - take a look at Themes/default/index.template.php for template_header_above() and template_main_above() and see what is required (notably, $modSettings, $settings, $options, $context, $txt, $user_info all have to have been defined)

It can be made to work, just not the way you're doing it: you have to start with SMF's code only, not start your own session on top of that (because that'll screw up SMF's session handler) and then call template_header(). If you really must do all that extra stuff, do so only after having called template_header() and expect it 1) to be slower and 2) likely to break if you do any of your own session handling after that.
Holder of controversial views, all of which my own.


CoffeeAddict

This would be the point where I get completely lost. I'm trying to follow but I don't have a clue what I should be doing next, I have some php knowledge but it's pretty basic.

Do I just call the template_header function above the include line for my header file, in the index template? (probably not, but this is all I can get from that...)

Arantor

Assuming you've gone through all the setup that SMF requires, and the session has been loaded, you just called template_header(). (Oh, and you'll want template_footer() after that to end the page markup/layout)

The problem is that your code is probably not going to work very well with what SMF does.
Holder of controversial views, all of which my own.


CoffeeAddict

Ok, I will give this a try and report back. Thank you!

I do eventually want to integrate the forum with the rest of the website, so users can register and login just once, however I've got two separate databases already (site and forum) and already have existing users in each...so I'm lost there as well, otherwise I think it sounds like it'd be better to integrate the forum completely instead of trying to use my own code/sessions.

For now I'd be happy to just get a username in the upper corner of the header, it seems like a more reasonable goal.

Advertisement: