Prevent re-submission of comment form

I have a comment form for the article, and I would have to prevent resubmission. I notice that Worpdress does this very well (return does not force the browser to request a re-submission of the form), but I cannot understand how they do it, although our methods are very similar.

My script

User visits mydomain.com/article/1/article_title.html

Fills out a form that places at mydomain.com/addnewcomment/1.html

Then I redirect 302 back to mydomain.com/article/1/article_title.html

Now, if I return from this position, it does not request a redirect. However, if I go to another page, for example. mydomain.com/tag/1/my_tag.html and click to resubmit the form.

Obviously, I want to prevent this.

What Wordpress does

A user visits mydomain.com/?p=1 Fills out a form in which messages are posted mydomain.com/wp-comments-post.php Then he redirects 302 back to mydomain.com/?p=1

Sending back or visiting another page and canceling does not lead to re-sending.

I looked at the WP code, but I do not see how they do it. Obviously, this is what I would like to achieve.

Does anyone have any thoughts on where I might be wrong?

(I use Wordpress as an example only to prove that this is possible, obviously, I am not trying to duplicate WP exactly, it would be pointless)

EDIT - Find out what it was for

, , ( , , ).

, , , .

, , , .

, , :

Content-Type Etag Content- Cache-Control Pragma

, , , - pragma no-cache -revalidate .

, , , .

+3

Source: https://habr.com/ru/post/1743218/


All Articles