Hi, got a little problem here.
i have a page with a form set in post method. this leads to the "operation page" which insert, modify or delete a record in a database, then list the remaining records. the problem is that just after an operation, if someone click the reload button (or F5), the operation is done again. for the modify and delete, it's not really a trouble but for insert, it is ! i was wondering if a solution existed to clear the $_POST values. thanks !
How to flush $_POST values after operation ?
use the [man]unset[/man] to clear the varaible after the ops are complete
nope, it don't work. i've tried to unset each var then unset $_POST directly but neither will work.
i'm thinking of a message page posting the result, that would be auto-redirected to the listing after a few seconds but i think there must be a cleaner way to do this.
thanks for the tips though.
change the cache to no-cache to stop the user from storing the data on the client machine. assign the $_POST vars to local vars inside the script and kill them at the end.
the no-cache [man]header[/man]s are
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
?>
wont work either. seems like i'll have to resort on using the msg page i mentionned b4. thanks anyway for your trouble.
heh, been some time since i've been here
the solution was simple : use a redirection header
after the operation is done, use
header('HTTP/1.1 301 Moved Permanently');
header('Location: page.php');
header('Connection: close');
exit();
the exit is optional, the header Location should do the trick, but just in case. This way, you reload the page without all the parameters that make it do an operation. Best would be to put it in a different page. One last thing, for the header() to work, there must be no output yet or it won't redirect (that includes error message to the user).