ToExeCute ToExeCute - 2 days ago 3x
PHP Question

PHP how to reset POST

I try to reset the Post's after I send the form.
In some threads I read that it could be

$_POST = array();

but when I tried it, it doesn't works.

Are there any solutions to reset the POST's?


In order to prevent a form from being re-submitted, you could do something like this - it should be pretty self explanatory:

function uniquePost($posted) {
    // take some form values
    $description = $posted['t_betreff'].$posted['t_bereich'].$posted['t_nachricht']; 
    // check if session hash matches current form hash
    if (isset($_SESSION['form_hash']) && $_SESSION['form_hash'] == md5($description) ) {
       // form was re-submitted return false
       return false;
    // set the session value to prevent re-submit
    $_SESSION['form_hash'] = md5($description);
    return true;

if (isset($_POST["t_submit"]) && uniquePost($_POST)) {
    $ticket_query   =   $db->prepare("INSERT INTO `ticket` (`Absender`, `Betreff`, `Abteilung`, `Prioritat`, `Erstellt`, `Nachricht`) VALUES (:sender, :betreff, :abteilung, :priority, :datum, :nachricht)");
    'sender'    =>  $_SESSION["id"],
    'betreff'   =>  $t_betreff,
    'abteilung' =>  $t_bereich,
    'priority'  =>  $t_priority,
    'datum'     =>  date('d.m.Y'),
    'nachricht' =>  $t_nachricht                                        
    // no need to reset the post variables