You have to redirect with the location header after each message, because otherwise, when the user clicks the refresh button, he will send the same form again ...
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { file_put_contents('data.txt', $_POST['data']); header('location: ' . $_SERVER['PHP_SELF']); } else { header('content-type: text/html; charset=utf-8'); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="application/x-www-form-urlencoded; charset=utf-8"> <input name="data" type="text" value="<?php echo file_get_contents('data.txt'); ?>"/> <button>küldés</button> </form> <?php }
Btw. if you want to do the right thing, you should try the PHP framework instead of this type of spaghetti code ...
source share