Inline Code Example HereHi,
the php code which

<html>
<body>
<?php 
$fs =fopen("comments.txt",'a');
$jina = $_POST["fname"];
$message = $_POST["message"];
$time = date("d/m/y : H:i:s", time()) ;
//limit leght characters
//$message = wordwrap($message, 5);
fwrite($fs,$message);
fwrite($fs, "\n<i>Posted By </i> ".$jina." <i>on </i>");
fwrite($fs, $time);
fwrite($fs, "<hr />");
$fs= fopen("comments.txt", 'r');
while (!feof($fs))
{
echo fgets($fs)."<br />";
}
fclose($fs);
/*<html>
<body onLoad="location.href='#chini'">
//<a name="chini"> </a>
</body>
</html>
*/
?>
</body>
</html>

writes the contents to the txt file, but the problem is when I click refresh button it writes the data as many times as I refresh the page. how can I avoid it.
Regards

Member Avatar for diafol

A script like this could be a standalone which then redirects back to the original page.

You could use a flag variable to prevent the code runnign again, e.g. with sessions or use a cookie - but cookies can be turned off.

form page -> filecreator -> form page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.