API16

JSession/fork: Difference between revisions

From Joomla! Documentation

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...
 
m clean up
Line 2: Line 2:
Create a new session and copy variables from the old one
Create a new session and copy variables from the old one


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JSession/fork|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JSession/fork}}
 
{{subst:Description:JSession/fork}}


===Syntax===
===Syntax===
Line 60: Line 58:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JSession/fork|Edit See Also]]<nowiki>]</nowiki>
{{subst:SeeAlso:JSession/fork}}
</span>
{{SeeAlso:JSession/fork}}


===Examples===
===Examples===

Revision as of 14:23, 24 March 2017

Description

Create a new session and copy variables from the old one


{{subst: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;
}


{{subst:SeeAlso:JSession/fork}}

Examples

<CodeExamplesForm />