comments are being saved twice on a file when i refresh the webpage

i am writing a comment block in my website.
i save the comment in a file and print the contents on the webpage.
but the problem is when i refresh the webpage the last comment gets displayed twice.

Here’s my code:
i am writing a comment block in my website.
i save the comment in a file and print the contents on

the webpage.
but the problem is when i refresh the webpage the last

comment gets displayed twice.

Here’s my code:

<html>


<body>

<form   method="GET">

<textarea rows="15" cols="50" name="comments" >
</textarea>

<input type="submit" value="submit" >

</form>

</body>
</html>



<?php


if(!($_GET["comments"]==null)){
$comments = "Anonymous said:<br>".$_GET

["comments"]."<br><br><br><br>";
$file_comments = fopen("comments.txt","a");
fwrite($file_comments,$comments);
fclose($file_comments);

$_GET["comments"] = null;
$comments = null;

}


$comments = file_get_contents("comments.txt");
echo $comments;


$_GET["comments"] = null;
$comments = null;

?>

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories