Welcome Guest, Not a member yet? Register   Sign In
How to clear POST data after processing??
#1

[eluser]123wesweat[/eluser]
Each time i reload the page it keeps sending the data into the db. So how can i clear the $_POST???
Code:
$res = $this->form_model->insert_data();
                    if($res == 1) {
                        $data['successmsg'] =  $this->load->view('forms/thank_you','',true);
                        $this->load->view($data['showContent']['content_tmpl'], $data);
                        $_POST[] = '';//didn't work
                        //return false;
                    }
#2

[eluser]mikelbring[/eluser]
What I sometimes do is redirect the user to the returned page after doing what is suppose to be posted. But I am sure there is a better solution. Interested in knowing what.
#3

[eluser]danmontgomery[/eluser]
Code:
$_POST[] = '';

This wouldn't clear any array, it just appends a blank string to the end of it.

Code:
unset($_POST); unset($_REQUEST);

Should work... mikelbring's reply works just as well too.
#4

[eluser]mikelbring[/eluser]
Hes worried about someone refreshing and being able to resubmit the post. I do not think unsetting them will work, but I haven't ever tried it either.
#5

[eluser]danmontgomery[/eluser]
Ah, then yes, you would have to redirect.
#6

[eluser]mikelbring[/eluser]
Problem I see is thats creating a 301 redirect overhead. Maybe there is some http-header magic you can do.
#7

[eluser]bretticus[/eluser]
Doing a redirect is pretty standard actually. However, you could also do a duplicate record query before committing the insert. There is no state in HTTP, you can't just clear POST.




Theme © iAndrew 2016 - Forum software by © MyBB