You should redirect with a location header after every post, because otherwise when the user presses the refresh button, it will send again the same form...
<?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 proper work, you should try out a php framework instead of this kind of spaghetti code...