View Full Version : PHP Sessions
JonnyH
October 21st, 2007, 12:36
I don't know if this is the most efficent way to do this, but I'm working on a errors function on the admin panel. So wherever you place <%ERRORS%> on the HTML it shows the errors which are set. It works and all but when you switch pages it still shows the errors, which I wan't to clear. I was looking at ob_start etc to get this working but I couldn't really get it.
Yun
October 21st, 2007, 13:03
www.php.net/session_destroy
Would that do what you want?
JonnyH
October 21st, 2007, 13:04
No because it destroys the session on page load so it doesn't show the error. Thanks tho.
krakjoe
October 21st, 2007, 15:32
you should unset( $_SESSION['errors'] ); before you set any new ones on every page load
or, you could write a method like
function getErrors( )
{
$errors = $_SESSION['errors'];
$_SESSION['errors'] = array( );
return $errors ;
}
so that when your HTML displays the errors they are unset in the session
JonnyH
October 21st, 2007, 15:40
That's the thing, when the errors are set, it'll refresh the page. So it'll reset it before it even shows it.
EDIT: That function Joe won't show the errors when set. On the page refresh.
stuffradio
October 22nd, 2007, 03:38
Why does it refresh when you show the errors?
JonnyH
October 22nd, 2007, 10:44
For example, when I submit data in the config of the admin area it'll refresh the page and update the data which was entered.
Yun
October 22nd, 2007, 11:42
If the page refreshes, then the session data would be carried forward to the new page, which also includes the errors.
So assuming you output the errors on the new page (after refreshing).
What krakjoe gave you would be okay, wouldn't it?
You just have to throw his code at the below where the error is outputted.
JonnyH
October 22nd, 2007, 11:44
If the page refreshes, then the session data would be carried forward to the new page, which also includes the errors.
So assuming you output the errors on the new page (after refreshing).
What krakjoe gave you would be okay, wouldn't it?
You just have to throw his code at the below where the error is outputted.
Then the problem is that it carries onto every page.
JonnyH
October 22nd, 2007, 11:49
Doesn't matter. Fixed it with some thinking.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.