我有许多网站经常受到多个IP地址暴力攻击。我使用了非常好的限制登录尝试,这会让他们反弹,但登录是一件痛苦的事,更不用说服务器资源的消耗了。尤其是当一些攻击是IP欺骗或访问大量数据时。
因此,我修改了一段代码,将查询字符串添加到登录中(感谢https://gist.github.com/williejackson) 并将其制作成一个“快速响应”插件,我可以将其放在当前受到攻击的网站上。
从本质上讲,它通过将查询变量添加到/wp-login.php eg公司/wp-login.php?question=answer
我的问题是重定向会发生什么?
有/wordpress/wp-admin 或/wp-admin 我经常使用的是/admin (这是我提供给客户的,因为它非常方便用户)这两种方法都不能传递查询字符串。
我也很好奇;我在任何地方都找不到/admin - 有人在时间的迷雾中提出了好主意现在还不清楚在哪里可以连接到重定向wp-admin 保留查询字符串。
目前来看,这段代码(我将在下面附上)只是暂时用作紧急修复,因为它还会破坏任何其他登录功能,如丢失密码或登录失败,但我想进一步开发它来处理这些实例。
<?php
/*
* Check the URL of the WordPress login
* page for a specific query string
*
* assumes login string is
* http://example.com/wp-login.php?question=answer
*/
function rkv_login_stringcheck() {
// set the location a failed attempt goes to
$redirect = \'http://www.google.com/\';
// missing query string all together
if (!isset ($_GET[\'question\']) )
wp_redirect( esc_url_raw ($redirect), 302 );
// incorrect value for query string
if ($_GET[\'question\'] !== \'answer\' )
wp_redirect( esc_url_raw ($redirect), 302 );
}
add_action( \'login_init\', \'rkv_login_stringcheck\' );
SO网友:butlerblog
有/wordpress/wp-admin或/wp-admin,我经常使用的是/admin(这是我提供给客户的,因为它非常方便用户),它们都不能传递查询字符串。
如果我理解你的意思,我想你要找的是wp_redirect_admin_locations() 使用函数。
这是一个规范函数,它定义管理位置并根据请求的URL处理重定向。
WP将此函数应用于template_redirect, 优先级为1000。这意味着任何只应用此an的修订版本的人都会使用操作挂钩(10)的默认优先级,自定义版本将启动并重定向用户。简单地说,您可以编写自己的版本,并处理传递任何必要的查询字符串。
// WP\'s default
add_action( \'template_redirect\', \'wp_redirect_admin_locations\', 1000 );
// At default priority, your custom version will kick in before WP\'s.
add_action( \'template_redirect\', \'my_custom_redirect_admin_locations\' );
(注意:我省略了编写自定义版本
wp_redirect_admin_locations() 你可能已经掌握了如何做到这一点。此外,我建议在任何自定义处理中都有一定的余地,以便在没有应用自定义情况的情况下继续执行,并最终达到默认值。)