Stop script execution after refresh

1.3k views Asked by At

I wrote a single program using html and javascript which contains a submit button. The problem that I have is that when I refresh my page, it's like I pressed submit button again!! But what I want is to NOT execut the script if I refresh the page. I don't know if it's clear but it's like that I want the program to get intialized if i refresh my page instead of executing a previous script !

1

There are 1 answers

0
BadHorsie On

I believe you are referring to the browser behaviour that is when you submit a form to the same page, if you refresh it will prompt you to resubmit the data again.

You can avoid this by issuing a redirect at the end of your script, to refresh the page and clear the history of the submit.

if (isset($_POST['submit'])) {

    // ... your code here

    header('Location: ' . $_SERVER['PHP_SELF']);
}