WordPress的安全问题是不容忽视的,如何知道他们的登录信息是否被泄露,他们的博客被反复尝试登录?今天,我为大家分享如何设置别人登录WordPress后台时发邮件提醒管理员呢?
后台登录成功提示
如果有人登录WordPress的后台,就会向电子邮件发送一封电子邮件,以提醒您某人已登录。如果您当时没有登录,您将处于戒备状态。
将以下代码放入主题的functions.php中:
/***************************************************** 函数名称:wp_login_notify 函数作用:有登录wp后台就会email通知博主 一淘模板 ******************************************************/function wp_login_notify(){ date_default_timezone_set('PRC'); $admin_email = get_bloginfo ('admin_email'); $to = $admin_email; $subject = '你的博客空间登录提醒'; $message = '你好!你的博客空间(' . get_option("blogname") . ')有登录!
' . '请确定是您自己的登录,以防别人攻击!登录信息如下:
' . '登录名:' . $_POST['log'] . '
' . '
登录密码:' . $_POST['pwd'] . '
' . '
登录时间:' . date("Y-m-d H:i:s") . '
' . '
登录IP:' . $_SERVER['REMOTE_ADDR'] . '
'; $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); $from = "From: "" . get_option('blogname') . "" "; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers );} add_action('wp_login', 'wp_login_notify');
后台登录失败提示
/***************************************************** 函数名称:wp_login_failed_notify 一淘模板 函数作用:有错误登录wp后台就会email通知博主******************************************************/function wp_login_failed_notify(){ date_default_timezone_set('PRC'); $admin_email = get_bloginfo ('admin_email'); $to = $admin_email; $subject = '你的博客空间登录错误警告'; $message = '你好!你的博客空间(' . get_option("blogname") . ')有登录错误!
' . '请确定是您自己的登录失误,以防别人攻击!登录信息如下:
' . '登录名:' . $_POST['log'] . '
' . '
登录密码:' . $_POST['pwd'] . '
' . '
登录时间:' . date("Y-m-d H:i:s") . '
' . '
登录IP:' . $_SERVER['REMOTE_ADDR'] . '
'; $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); $from = "From: "" . get_option('blogname') . "" "; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers );} add_action('wp_login_failed', 'wp_login_failed_notify');
有人试图登录到您的系统,但它不起作用。这种重复的尝试将会被记录下来并发送给博主,如果有登录失败的记录,就会向您的邮箱发送电子邮件,发送其他人尝试到您邮箱的登录名和登录密码。
发表评论
共有[ 3 ]人发表了评论