Discuz clears the session, causing the session storage mechanism to fail and the session cannot be updated and resolved.

Source: Internet
Author: User

[Php]
 
 
 
<? Php
 
Function userErrorHandler (){
$ E = func_get_args ();
Echo '<pre style = "color: red;"> <br/> ---------- run error ---------: <br/> '. print_r ($ e, 1 ). '<br/> ---------- running error --------- <br/> </pre> ';
}
Set_error_handler ("userErrorHandler ");
Set_exception_handler ("userErrorHandler ");
 
Function shutdown (){
$ A = error_get_last ();
If ($! = Null) echo '<pre style = "color: red;"> <br/> ++ low-level error ++ <br/> '. print_r ($ a, 1 ). '<br/> ++ low-level error ++ <br/> </pre> ';
}
 
Register_shutdown_function ('shutdown '); // If exit is used, this script is not run.
 
 
Switch ($ _ GET ['who']) {
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 --------- <br/> ';
Var_dump ($ _ SESSION );
Echo '<br/> edit ------- </br/> ';
$ _ SESSION ['qidizi'] = 'qidiziclean ';
Var_dump ($ _ SESSION );
Echo '<br/> under clean --------- <br/> ';
$ GLOBALS ['_ SESSION'] = null; unset ($ GLOBALS ['_ SESSION']); // After unset, the session will become invalid.
Empty ($ GLOBALS ['_ session']) & ($ GLOBALS [' _ session'] ['qidizirebuid'] = '1 '); // This sentence cannot be rebuilt/re-trigger the session storage mechanism
Session_write_close (); // Save the session change in advance. If discuz clears the session, the saving mechanism fails. by qidizi, this statement is valid and submitted for saving.
Var_dump ($ _ SESSION );
Break;
}

 


<? Php

Function userErrorHandler (){
$ E = func_get_args ();
Echo '<pre style = "color: red;"> <br/> ---------- run error ---------: <br/> '. print_r ($ e, 1 ). '<br/> ---------- running error --------- <br/> </pre> ';
}
Set_error_handler ("userErrorHandler ");
Set_exception_handler ("userErrorHandler ");

Function shutdown (){
$ A = error_get_last ();
If ($! = Null) echo '<pre style = "color: red;"> <br/> ++ low-level error ++ <br/> '. print_r ($ a, 1 ). '<br/> ++ low-level error ++ <br/> </pre> ';
}

Register_shutdown_function ('shutdown '); // If exit is used, this script is not run.


Switch ($ _ GET ['who']) {
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 --------- <br/> ';
Var_dump ($ _ SESSION );
Echo '<br/> edit ------- </br/> ';
$ _ SESSION ['qidizi'] = 'qidiziclean ';
Var_dump ($ _ SESSION );
Echo '<br/> under clean --------- <br/> ';
$ GLOBALS ['_ SESSION'] = null; unset ($ GLOBALS ['_ SESSION']); // After unset, the session will become invalid.
Empty ($ GLOBALS ['_ session']) & ($ GLOBALS [' _ session'] ['qidizirebuid'] = '1 '); // This sentence cannot be rebuilt/re-trigger the session storage mechanism
Session_write_close (); // Save the session change in advance. If discuz clears the session, the saving mechanism fails. by qidizi, this statement is valid and submitted for saving.
Var_dump ($ _ SESSION );
Break;
}
The above is the test code

 


The key is in $ GLOBALS ['_ session'] = null; and

[Php]
Unset ($ GLOBALS ['_ session']);

Unset ($ GLOBALS ['_ SESSION']); will cause the session to fail to save the session after resolution, which looks like this. I don't know how the automatic session storage mechanism works. the simple reconstruction in the Code does not trigger the Save mechanism.

Therefore, I used the call method to save my session Changes in advance.


Global variables are cleared in the discuz_application class,

Because
Positive variables do not need to be retained,


Var $ superglobal = array (
'Globals' => 1,
'_ Get' => 1,
'_ Post' => 1,
'_ Request' => 1,
'_ Cookies' => 1,
'_ Server' => 1,
'_ Env' => 1,
'_ Files' => 1,
);

Then the front code is cleared.

 

Foreach ($ GLOBALS as $ key => $ value ){
If (! Isset ($ this-> superglobal [$ key]) {
$ GLOBALS [$ key] = null; unset ($ GLOBALS [$ key]);
}
}

The final result shows the following code functions:
The key is in $ GLOBALS ['_ session'] = null.

Use the above test code for Demonstration:
The positive argument is local. q/t. php? How = s (SET) | g (get) | u (modify) | c (clear)

Step 1: set-> Get-> modify-> Get === result. The modification can be fed back to the obtained result.
Step 2: set-> Get-> modify-> Get-> clear-> Get === result: the data is normal after the modification is obtained. an error occurred while obtaining the cleared data. The modified data was obtained. (Note that the tests here are not mentioned in advance)

 

The problem is that the init method of disucz causes the same effect to be cleared. In some cases, the session cannot be cleared. Simply, the verification code can be submitted infinitely once entered.

Although it can be prevented by other methods, the normal mechanism of this session is damaged. There are many problems.

At present, when I write this, I still don't know what method can be used to restore its mechanism. The above method does not work.

 

 

 




 

 

 


After testing, we found that using session_write_close (); Save the session rationality in advance. This will solve my problem. I don't know why the automatic saving will fail after clearing the session. You need to save it manually.

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.