WordPress | 2023年12月21日11:37:10
WordPress目前最新版本仍有搜索安全漏洞,攻击者可利用此漏洞对WordPress站点产生大量恶意搜索请求,会导致服务器CPU高负载运行,甚至有可能造成MySQL停止服务,网站无法打开。
一、在以下选择符合自己需求的代码,再复制代码。
禁止游客身份使用搜索功能,游客使用搜索后,页面会自动转到网站首页。
//禁止游客身份使用搜索功能 function disable_search_for_guests() { if (!is_user_logged_in() && is_search()) { wp_redirect(home_url()); exit(); } } add_action('template_redirect', 'disable_search_for_guests');
给游客身份设置搜索限制,例如5分钟使用一次搜索功能,5分钟内再次使用搜索功能会自动转向网站首页。
//设限游客身份5分钟使用一次搜索功能 function limit_search_for_guests() { if (!is_user_logged_in() && is_search()) { $last_search_time = get_transient('last_search_time'); $current_time = time(); if (!$last_search_time || ($current_time - $last_search_time) > 300) { set_transient('last_search_time', $current_time, 300); } else { wp_redirect(home_url()); exit(); } } } add_action('template_redirect', 'limit_search_for_guests');
二、进入WordPress后台 > 外观 > 主题文件编辑器 > 点击模板函数文件(funtions.php) > 把代码粘贴到此文件内 > 最后点击"更新文件"
本文标题:WordPress禁止游客身份使用搜索功能 或限制游客5分钟使用一次搜索功能
本文链接:https://bufanz.com/post/303.html
版权声明:本文章是 不凡博客(Bufanz.com) 的原创文章,未经允许请勿转载本文章!
相关文章
网友点评 展开评论
本文暂无评论 - 欢迎您