API16:JSession/fork
From Joomla! Documentation
Description
Create a new session and copy variables from the old one
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;
}
Examples
Code Examples