JSession/fork: Difference between revisions
From Joomla! Documentation
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 preparing for archive only |
||
| (One intermediate revision by the same user not shown) | |||
| 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 | ||
===Syntax=== | ===Syntax=== | ||
| Line 60: | Line 58: | ||
</source> | </source> | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=fork | category=fork | ||
category=JSession | category=JSession | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
Latest revision as of 02:03, 25 March 2017
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