Home > Backend Development > PHP Tutorial > PHP code that blocks bots from harvesting email addresses from your website

PHP code that blocks bots from harvesting email addresses from your website

高洛峰
Release: 2023-03-02 17:42:02
Original
1050 people have browsed it

Spam is very annoying. Here is a method to automatically block robots from collecting email addresses from your website.
Copy code The code is as follows:
function security_remove_emails($content) {
$pattern = '/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+. [a-zA-Z]{2,4})/i';
$fix = preg_replace_callback($pattern,
"security_remove_emails_logic", $content);

return $fix;
}
function security_remove_emails_logic($result) {
return antispambot($result[1]);
}
add_filter( 'the_content', 'flex_remove_emails', 20 );
add_filter( 'widget_text', 'flex_remove_emails', 20 );

Put this in functions. In the php file, if a robot collects email addresses, it will be automatically blocked.

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template