{"id":219937,"date":"2023-01-20T14:02:00","date_gmt":"2023-01-20T11:02:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=219937"},"modified":"2023-01-29T09:57:36","modified_gmt":"2023-01-29T06:57:36","slug":"luchshee-jeffektivnoe-sredstvo-obnaruzhenija-php-koda-dlja-zashhity-ot-spama-dlja-wordpress","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/ru\/luchshee-jeffektivnoe-sredstvo-obnaruzhenija-php-koda-dlja-zashhity-ot-spama-dlja-wordpress\/","title":{"rendered":"\u041b\u0443\u0447\u0448\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f PHP-\u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0441\u043f\u0430\u043c\u0430 \u0434\u043b\u044f WordPress"},"content":{"rendered":"\n<p>\u0411\u043b\u043e\u0433 WordPress \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 100 \u0441\u043f\u0430\u043c-\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 (\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043f\u0430\u043c-\u0440\u043e\u0431\u043e\u0442\u0430\u043c\u0438) \u0432 \u0434\u0435\u043d\u044c, \u0447\u0442\u043e \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0435\u0442.<\/p>\n<p><a href=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfcecc6e1.jpg\" data-rel=\"lightbox\"><img decoding=\"async\" class=\"SDStudio-light-box-enable SDStudio-editor-tools-md-imp\" src=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfcecc6e1.jpg\" alt=\"\u041b\u0443\u0447\u0448\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f PHP-\u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0441\u043f\u0430\u043c\u0430 \u0434\u043b\u044f Wordpress\"><\/a><\/p>\n<p>wordpress-\u0441\u043f\u0430\u043c<\/p>\n<p>\u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u044b \u043f\u043b\u0430\u0433\u0438\u043d\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a Akismet, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 <a href=\"https:\/\/wordpress.mediadoma.com\/ru\/sokrashhenie-ispolzovanija-bazy-dannyh-wordpress\/\" title=\"\u0443\u0434\u0430\u043b\u0435\u043d\u044b\">\u0443\u0434\u0430\u043b\u0435\u043d\u044b<\/a> \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 <a href=\"https:\/\/wordpress.mediadoma.com\/ru\/kak-nastroit-php-skript-v-crontab-dlja-ochistki-neskolkih-wordpress-baz-dannyh-na-odnom-servere\/\" title=\"\u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0440\u043e\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\">\u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0440\u043e\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/a>.<\/p>\n<p><a href=\"https:\/\/leonax.net\/p\/6732\/block-spam-comments-from-web-page\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">LEONA<\/a> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0443\u043c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0441\u043f\u0430\u043c-\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0432 \u0444\u043e\u0440\u043c\u0435 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u0442 \u043a\u043b\u0430\u0432\u0438\u0448\u0443 (onkeyup). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u043c\u044b \u0434\u0443\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0447\u0435\u043b\u043e\u0432\u0435\u043a.<\/p>\n<p>wordpress \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440 <strong>preprocess_comment<\/strong>, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <strong>wp_die()<\/strong> \u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 API WP \u0433\u043e\u0432\u043e\u0440\u0438\u0442 (<a href=\"https:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/preprocess_comment\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">https:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/preprocess_comment<\/a> ), \u0447\u0442\u043e $commentdata \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e:<\/p>\n<pre><code>'comment_post_ID' \u00a0 \u00a0 \u00a0- The post to which the comment will apply\n\u00a0 \u00a0'comment_author' \u00a0 \u00a0 \u00a0 - (may be empty)\n\u00a0 \u00a0'comment_author_email' - (may be empty)\n\u00a0 \u00a0'comment_author_url' \u00a0 - (may be empty)\n\u00a0 \u00a0'comment_content' \u00a0 \u00a0 \u00a0- The text of the proposed comment\n\u00a0 \u00a0'comment_type' \u00a0 \u00a0 \u00a0 \u00a0 - 'pingback', 'trackback', or empty for regular comments\n\u00a0 \u00a0'user_ID' \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0- (empty if not logged in)<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u043b\u0430\u0433\u0438\u043d, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c pingback\/trackback (\u0447\u0442\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u043e\u043b\u0435\u0437\u043d\u043e) \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u043f\u0430\u043c-\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<pre><code>$leonax_magic_lower = 328;\n$leonax_magic_upper = 3450709;\n\u00a0\nfunction leonax_anti_spam_form($fields){\n\u00a0 \u00a0 global $leonax_magic_lower, $leonax_magic_upper;\n\u00a0 \u00a0 $leonax_magic = mt_rand($leonax_magic_lower, $leonax_magic_upper);\n\u00a0 \u00a0 $fields['leonax_magic'] = &lt;&lt;&lt;EOT\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;input type=\"hidden\" id=\"leonax-magic\" name=\"leonax-magic\" value=\"0\"&gt;\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;script type=\"text\/javascript\"&gt;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 jQuery(function() {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 jQuery(\"#comment\").on(\"keyup\", function() {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 jQuery(\"#leonax-magic\").val(\"$leonax_magic\");\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 });\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 })\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;\/script&gt;\nEOT;\n\u00a0 \u00a0 return $fields;\n}\n\u00a0\nadd_filter('comment_form_default_fields', 'leonax_anti_spam_form');\n\u00a0\nfunction leonax_anit_spam_caught() {\n\u00a0 wp_die('&lt;strong&gt;ERROR&lt;\/strong&gt;: Looks like you are a spam bot. Please stop doing this.');\n}\n\u00a0\nfunction leonax_anti_spam_check( $commentdata) {\n\u00a0 $comment_type = '';\n\u00a0 if (isset($commentdata['comment_type'])) {\n\u00a0 \u00a0 $comment_type = trim($commentdata['comment_type']);\n\u00a0 } \u00a0 \n\u00a0 \n\u00a0if (($comment_type == 'pingback') || ($comment_type == 'trackback')) {\n\u00a0 \u00a0 return $commentdata;\n\u00a0 }\n\u00a0 $content = '';\n\u00a0 if (isset($commentdata['comment_content'])) {\n\u00a0 \u00a0 $content = trim($commentdata['comment_content']);\n\u00a0 } \u00a0 \n\u00a0 if (!strlen($content)) {\n\u00a0 \u00a0 leonax_anit_spam_caught();\n\u00a0 }\n\u00a0 \n\u00a0 if (preg_match(\"\/[a-e0-9]{25,}\/i\", $content)) { \/\/ To capture the strange IDs\n\u00a0 \u00a0 leonax_anit_spam_caught(); \u00a0\n\u00a0 }\n\u00a0\n\u00a0 global $leonax_magic_lower, $leonax_magic_upper; \u00a0\n\u00a0 \n\u00a0 if (isset($commentdata['user_ID']) &amp;&amp; $commentdata['user_ID']) { \/\/ Login-users are not bad\n\u00a0 \u00a0 return $commentdata;\n\u00a0 }\n\u00a0 \n\u00a0 if (!isset($_POST['leonax-magic'])) {\n\u00a0 \u00a0 leonax_anit_spam_caught();\n\u00a0 }\n\u00a0 $magic = intval($_POST['leonax-magic']);\n\u00a0 if ($magic &lt; $leonax_magic_lower || $magic &gt; $leonax_magic_upper) {\n\u00a0 \u00a0 leonax_anit_spam_caught();\n\u00a0 }\n\u00a0 return $commentdata;\n}\n\u00a0\nadd_filter( 'preprocess_comment', 'leonax_anti_spam_check' );<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\/\u0444\u0438\u043b\u044c\u0442\u0440, \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0432\u0432\u0435\u0434\u044f \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 (\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043d\u0435 \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f).<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435. \u041f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 <strong>functions.php<\/strong> (\u0438\u043b\u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0439 \u0442\u0435\u043c\u044b).<\/p>\n<p><a href=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfd03126a.jpg\" data-rel=\"lightbox\"><img decoding=\"async\" class=\"SDStudio-light-box-enable SDStudio-editor-tools-md-imp\" src=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfd03126a.jpg\" alt=\"\u041b\u0443\u0447\u0448\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f PHP-\u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0441\u043f\u0430\u043c\u0430 \u0434\u043b\u044f Wordpress\"><\/a><\/p>\n<p>wordpress-\u0441\u043f\u0430\u043c-\u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/p>\n<p>\u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0432\u043e\u043b\u0448\u0435\u0431\u0441\u0442\u0432\u043e!<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0437\u0430\u043f\u0438\u0441\u0438:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041b\u0443\u0447\u0448\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f PHP-\u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0441\u043f\u0430\u043c\u0430 \u0434\u043b\u044f WordPress<\/p>\n","protected":false},"author":1,"featured_media":223984,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[809,870,1025,726,850],"tags":[1171],"class_list":["post-219937","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-ru","category-wordpress-ru","category-bezopasnost","category-rozrobnyk-ru","category-uchebniki-ru","tag-affiai-ru"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/posts\/219937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/comments?post=219937"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/posts\/219937\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/media\/223984"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/media?parent=219937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/categories?post=219937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/ru\/wp-json\/wp\/v2\/tags?post=219937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}