php - Clear session variable after use -
Is it possible to use a session variable, then unset it directly?
Example:
// ==== // Process form if ($ _POST ['submit']) {$ update = $ user settings & gt ; Update ($ _ POST); // If there are any form errors (if! $ Updates) {// load in an error $ errors = $ update [1]; } Else {// Set session $ $ _SESSION ['showUpdated'] = true; Redirect this page to // ("Location: http://www.mysite.com/settings"); }} // ================= If ($ _SESSION ['showUpdated']
After the form is submitted, if there is no error:
- Set up a session to set ($ _ session ['showUpdated' ];} Form submission was ok
- Reload the page (To prevent reposted POST data again)
- If the 'showUpdated' session variable Display the "updated" message
- Uninstall the session variable (so we do not see the message on the next reload)
on The problem in the bottom is that if you set the effect directly after the session;
Any solution? Is this the best way to do it?
Many thanks!
It looks like this should work. Make sure you call session_start () before using session , And always get out () or die after a redirect header.
I am completing that you do a slightly different way I have a 'message' element in the session. I had 'my data saved', er ror message, etc. Then, on each page (actually in a page template class), I check to see if the $ _ session ['message']
is set and is not empty if there is anything , Then I display the message and set an empty string or an empty value.
Comments
Post a Comment