API16

API16:JSession/fork

From Joomla! Documentation

Revision as of 22:42, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Create a new session and copy variables from the old one <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JSession/fork|Edit Descrip...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Create a new session and copy variables from the old one

[Edit Descripton]

Template:Description:JSession/fork

Syntax

fork()


Returns

boolean $result true on success

Defined in

libraries/joomla/session/session.php

Importing

jimport( 'joomla.session.session' );

Source Body

public function fork()
{
        if ($this->_state !== 'active') {
                // @TODO :: generated error here
                return false;
        }

        // save values
        $values = $_SESSION;

        // keep session config
        $trans  =       ini_get('session.use_trans_sid');
        if ($trans) {
                ini_set('session.use_trans_sid', 0);
        }
        $cookie =       session_get_cookie_params();

        // create new session id
        $id     =       $this->_createId(strlen($this->getId()));

        // kill session
        session_destroy();

        // re-register the session store after a session has been destroyed, to avoid PHP bug
        $this->_store->register();

        // restore config
        ini_set('session.use_trans_sid', $trans);
        session_set_cookie_params($cookie['lifetime'], $cookie['path'], $cookie['domain'], $cookie['secure']);

        // restart session with new id
        session_id($id);
        session_start();

        return true;
}

[Edit See Also] Template:SeeAlso:JSession/fork

Examples

<CodeExamplesForm />