News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

SMF 2 integration - session data is different

Started by chinmay235, March 04, 2015, 02:50:01 AM

Previous topic - Next topic

chinmay235

I am trying to use the http://wiki.simplemachines.org/smf/Integration_hooks#integrate_verify_user

So, I have created a file called `my_integrate_verify_user` in the forum folder, which has the following code:

    function my_integrate_verify_user()
    {
    var_dump($_SESSION); exit();
    }


Then I inserted the following entries into `smf_settings` table:

    INSERT INTO smf_settings (variable, value) VALUES
    ('integrate_pre_include', '/path/to/my_integrate_verify_user.php'),
    ('integrate_verify_user', 'my_integrate_verify_user');


Now, before I visit my forum, I load my site and login into it, which sets the following session data (to be used in the smf integration hook later):

    $_SESSION['IsLoggedIn'] = true;
    $_SESSION['LoggedInUser'] = 'hello123'; // Test


Now, when I visit the SMF forum (that is running my above hook), I see the following session data from SMF:

![enter image description here][1]

I am not seeing the session data that was set by my site.

P.s the urls are:

* http://mysite.local [nofollow] (this is where I login, which sets the above session data)
* http://mysite.local/forums [nofollow] (this is where the forums is installed)

If I visit my site, i am still logged in. However on the session var_dump in the hook, i don't see my session data. Any idea why this is? Some kind of scope issue?

margarett

I'm not sure if I can fully help you but here goes nothing :P

QuoteHowever on the session var_dump in the hook, i don't see my session data. Any idea why this is? Some kind of scope issue?
This happens because when you visit SMF, you loaded a full new page and, as such, a full new session (by SMF). At this point, anything that your site created in session is long gone...

I never used this, really, but I think you are doing it wrong...

I *think* you need to use some kind of "non-volatile" way of memorizing if your user is logged in in your site. A cookie is probably the best option, but any database interaction is also valid.
Then, in integrate_verify_user, you need to read that information and decide if the user is or is not logged. Finally, the integration function should return the user ID (in SMF!) of the logged user, or 0 if the user is not logged in.
If you don't return a value in that function (that value is the user ID of the logged user), then you will never be logged in...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

For the described use case, SSI is probably the way to solve this, not the hooks (certainly not the hooks the way they are apparently trying to be used)

Hooks are designed for telling SMF to use some other system as being logged in. Adding data to session should really be done with SSI when you can just include it and be told what user ID is already logged in without having to touch the session

Advertisement: