Prev |  | Next

### 3.18.2. user_session_create

Allow modules to override Phorum's session create management or to even fully omit creating a session (for example useful if the hook ??? is used to inherit an external session from some 3rd party application).

Call time:

Just before Phorum runs its own session initialization code in the user API function `phorum_api_user_session_create()`.

Hook input:

The session type for which a session must be created. This can be either `PHORUM_FORUM_SESSION` or `PHORUM_ADMIN_SESSION`.

Hook output:

Same as input if Phorum has to run its standard session initialization code or NULL if that code should be fully skipped.

Example code:

    function phorum_mod_foo_user_session_create($type)
    {
        // Let Phorum handle admin sessions on its own.
        if ($type == PHORUM_ADMIN_SESSION) return $type;

        // Override the session handling for front end forum sessions.
        // We could for example put the session in a standard PHP
        // session by first starting a PHP session if that was
        // not done yet...
        if (!session_id()) session_start();

        // ...and then storing the user_id of the current user in the
        // PHP session data. The user_id is really the only thing
        // that needs to be remembered for a Phorum session, because
        // all other data for the user is stored in the database.
        $phorum_user_id = $GLOBALS["PHORUM"]["user"]["user_id"];
        $_SESSION['phorum_user_id'] = $phorum_user_id;

        // Tell Phorum not to run its own session initialization code.
        return NULL;
    }

See the ??? hook for an example of how to let Phorum pick up this PHP based session.

Prev | Up | Next
| Home |