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

前端 未结 2 946
谎友^
谎友^ 2021-01-24 17:00

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 ge

2条回答
  •  离开以前
    2021-01-24 17:27

    The solution is to redirect to the same page. This will work, for example. Try it.

    
    
    
    " . $TextArea . "



    \n\n"; // Add \n\n to write the comments in a different paragraph inside the file. $file_comments = file_put_contents( "comments.txt", $comments, FILE_APPEND ); echo ''; } $comments = file_get_contents( "comments.txt" ); echo $comments; ?>

    Takes more time to refresh, though. The best way to do it is to have the PHP script in another file.

提交回复
热议问题