Home >Backend Development >PHP Tutorial >Solution to obtain the session value newly assigned in the current method in the same method_PHP tutorial
I encountered such a problem during project development. I assigned a value to the session array in the same method, but I wanted to use this session again in this method. Because I used if...elseif..., due to the repulsion effect, in the if condition After assigning a value to the session, and then calling the method to enter another elseif condition, the assignment in the previous step cannot be obtained. The solution is summarized as follows:
PHP SESSION has a function: session_write_close(). The function of this function is to write session data, save it and end the session.
The description of this function in the manual says: Session data is usually stored after your script terminated without the need to call session_write_close().
That is: session data is usually saved at the end of the script, unless you call session_write_close().
This problem is solved.