News:

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

Main Menu

Add Session Variable

Started by nclmccain, July 12, 2023, 03:10:11 AM

Previous topic - Next topic

nclmccain

I'm working on a project and I'm using the the SSI for user authentication and data. My question is usually when I code a form I'll restart the session and add a bit of data using the $_SESSION[] = data method. However since I'm using SMFs sessions I can't use my own sessions. How would I go about doing this using the existing sessions?

Thank you for the help.

live627

Hi, the relevant code is
    // Set the randomly generated code.
    if (!isset($_SESSION['session_var']))
    {
        $_SESSION['session_value'] = md5(session_id() . $smcFunc['random_int']());
        $_SESSION['session_var'] = substr(preg_replace('~^\d+~', '', sha1($smcFunc['random_int']() . session_id() . $smcFunc['random_int']())), 0, $smcFunc['random_int'](7, 12));
    }
    $sc = $_SESSION['session_value'];
https://github.com/SimpleMachines/SMF/blob/1eba72c227442c29046073ae40a48827f91337df/Sources/Session.php#L88-L94C35

Is this a login form?

nclmccain

Not for a login but to insert information into a database and then to add a variable to the session and returned to the original page so a success message can be displayed.

I usually do something like:

if ($insert) {
session_start();
$_SESSION['msg'] = 1;
// return to original page
}

if(!empty($_SESSION['msg'])) {
//message here
unset($_SESSION['msg']);
}

Advertisement: