Portfolio
My Blog
Scroll down to discover
Search
Categories

Chặn comment spam bằng Cloudflare WAF

September 4, 2025Category : Code/Web

Sử dụng Cloudflare WAF tạo 1 rule

Truy cập vào Cloudflare -> Security -> WAF -> Create rule -> Edit expression

  • Rule name (required): đặt 1 tên tùy ý để nhớ
  • If incoming requests match…  điền vào
(http.request.uri contains "wp-comments-post.php" and http.request.uri.query ne "bdad9e2ef62632b042bdc9b8b1907c87")

Có thể thay bdad9e2ef62632b042bdc9b8b1907c87 bằng 1 dãy số khác tùy ý cho riêng bạn

  • Then take action… chọn Block

Sau đó ấn vào Desloy

Sử dụng Code Snippets tạo 1 file php với nội dung:

function correct_comment_url_on_scroll() { // Check if Comment is enabled if(comments_open()) echo '<script> let commentForm = document.querySelector("#commentform, #ast-commentform, #ht-commentform"); // Load new comment path on the scroll event document.onscroll = function () { commentForm.action = "/wp-comments-post.php?bdad9e2ef62632b042bdc9b8b1907c87"; }; </script>'; } add_action('wp_footer', 'correct_comment_url_on_scroll', 99);

Nếu ở bước Cloudflare WAF bạn thay bdad9e2ef62632b042bdc9b8b1907c87 bằng 1 dãy số khác thì sửa bên trong Code Snippets về con số này

 

01.
© Oliver / All rights reserved.
To top