Discuz empty session, resulting in session save mechanism failed, session cannot update and solve _php tutorial

Source: Internet
Author: User
[PHP]




function Usererrorhandler () {
$e = Func_get_args ();
Echo '

----------Run an error---------:
'. Print_r ($e, 1). '
Error----------running---------
';
}
Set_error_handler ("Usererrorhandler");
Set_exception_handler ("Usererrorhandler");

function shutdown () {
$a =error_get_last ();
if ($a! = null) echo '

++++++ low-level error +++++
'. Print_r ($a, 1). '
++++++ low-level error +++++
';
}

Register_shutdown_function (' shutdown ');//If you use Exit, this script will not run


Switch ($_get[' how ')} {
Case ' s '://set
Session_Start ();
$_session[' Qidizi ' = rand ();
echo $_session[' Qidizi '];
Break
Case ' u '://unset
Session_Start ();
$_session[' qidizi '] = ' qidiziunset ';
echo $_session[' Qidizi '];
Break
Case ' G '://get
Session_Start ();
Var_dump ($_session);
Break
Case ' C '://clean
Session_Start ();
Echo ' Get---------
';
Var_dump ($_session);
Echo '
Edit-------
';
$_session[' qidizi '] = ' qidiziclean ';
Var_dump ($_session);
Echo '
Under Clean---------
';
$GLOBALS [' _session ']=null;unset ($GLOBALS [' _session ']), the SESSION will expire after//unset
Empty ($GLOBALS [' _session ']) && ($GLOBALS [' _session '] [' qidizirebuid '] = ' 1 ');//This sentence does not reconstruct/re-trigger the SESSION save mechanism
Session_write_close ();//save session changes in advance, Discuz clears the session resulting in the failure of the save mechanism, by Qidizi, this sentence is valid, commit to save
Var_dump ($_session);
Break
}


function Usererrorhandler () {
$e = Func_get_args ();
Echo '


----------Run an error---------:
'. Print_r ($e, 1). '
Error----------running---------
';
}
Set_error_handler ("Usererrorhandler");
Set_exception_handler ("Usererrorhandler");

function shutdown () {
$a =error_get_last ();
if ($a! = null) echo '


++++++ low-level error +++++
'. Print_r ($a, 1). '
++++++ low-level error +++++
';
}

Register_shutdown_function (' shutdown ');//If you use Exit, this script will not run


Switch ($_get[' how ')} {
Case ' s '://set
Session_Start ();
$_session[' Qidizi ' = rand ();
echo $_session[' Qidizi '];
Break
Case ' u '://unset
Session_Start ();
$_session[' qidizi '] = ' qidiziunset ';
echo $_session[' Qidizi '];
Break
Case ' G '://get
Session_Start ();
Var_dump ($_session);
Break
Case ' C '://clean
Session_Start ();
Echo ' Get---------
';
Var_dump ($_session);
Echo '
Edit-------
';
$_session[' qidizi '] = ' qidiziclean ';
Var_dump ($_session);
Echo '
Under Clean---------
';
$GLOBALS [' _session ']=null;unset ($GLOBALS [' _session ']), the SESSION will expire after//unset
Empty ($GLOBALS [' _session ']) && ($GLOBALS [' _session '] [' qidizirebuid '] = ' 1 ');//This sentence does not reconstruct/re-trigger the SESSION save mechanism
Session_write_close ();//save session changes in advance, Discuz clears the session resulting in the failure of the save mechanism, by Qidizi, this sentence is valid, commit to save
Var_dump ($_session);
Break
}
The above is the test code


The key is in the $GLOBALS [' _session ']=null; This sentence. and

[PHP]
unset ($GLOBALS [' _session ']);

unset ($GLOBALS [' _session ']); the mechanism that will allow the session to save the session at the end of the parsing process fails, and it looks like this. The mechanism of the session auto-save is not understood. A simple rebuild in the demo code does not trigger a save mechanism.

So, later I used the advance call method to save my session changes in advance.


The global variables are emptied in the Discuz_application class.

Because
Front face variables do not need to be preserved,


var $superglobal = Array (
' GLOBALS ' = 1,
' _get ' = 1,
' _post ' = 1,
' _request ' = 1,
' _cookie ' = 1,
' _server ' = 1,
' _env ' = 1,
' _files ' = 1,
);

And then the front code clears it.

foreach ($GLOBALS as $key = = $value) {
if (!isset ($this->superglobal[$key])) {
$GLOBALS [$key] = null; Unset ($GLOBALS [$key]);
}
}

The final effect appears as follows code function
The key is in the $GLOBALS [' _session ']=null; This sentence.

Use the test code above to demonstrate:
Positive statement refers to Local.q/t.php?how=s (set) |g (GET) |u (Modify) |c (empty)

Operation Step 1 settings, get, modify, get = = result, modify can feed back to the result of the acquisition
Operation Step 2, get it, and modify it, get it, and get it. Results: Get modified data is OK. Failed to get the emptied data and obtained the data when it was modified. (Note that the test here is not put in advance)

The problem is that the Init method of Disucz causes the same effect to be emptied. Results in some cases the use of the session will not be able to remove the problem. Simple is to cause the verification code input once can be unlimited commit.

Although other methods can be used to prevent it. But the normal mechanism of the session was destroyed. There are more problems.

At the moment I am writing this, it is not clear what method can be used to restore its mechanism. The method above does not work.





The test found using Session_write_close (); Save session rationality in advance. You can solve the problem I encountered, I do not know why after clearing the session, automatic saving will be invalidated. You need to save it proactively.

http://www.bkjia.com/PHPjc/477298.html www.bkjia.com true http://www.bkjia.com/PHPjc/477298.html techarticle [PHP]? PHP function Usererrorhandler () {$e = Func_get_args (); Echo Pre style=color:red;br/----------run error---------: Br/.print_r ($e, 1). br/----------Run error---------br// ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.