WordPress站点出现404错误时邮件通知管理员
发布:smiling 来源: PHP粉丝网 添加日期:2014-03-18 14:45:08 浏览: 评论:0
一个比较好玩的功能就是当我们网站出现了错误时就邮箱通知管理员了,将下面的代码添加到你所用的WordPress主题的 404.php 文件的顶端即可.
如果你的主机支持mail()函数或者设置了SMTP发送邮件,总之就是能够发送邮件就行,一会去查看你设置的WordPress站点的管理员邮箱,你就会发现404通知邮件,可能在垃圾箱哦.
实例代码如下:
- mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email");
否则我们按下面方法来操作,代码如下:
- <?php // WP 404 ALERTS
- // set status
- header("HTTP/1.1 404 Not Found");
- header("Status: 404 Not Found");
- // site info
- $blog = get_bloginfo('name');
- $site = get_bloginfo('url') . '/';
- $email = get_bloginfo('admin_email');
- // theme info
- if (!emptyempty($_COOKIE["nkthemeswitch" . COOKIEHASH])) {
- $theme = clean($_COOKIE["nkthemeswitch" . COOKIEHASH]);
- } else {
- $theme_data = wp_get_theme();
- $theme = clean($theme_data->Name);
- }
- // referrer
- if (isset($_SERVER['HTTP_REFERER'])) {
- $referer = clean($_SERVER['HTTP_REFERER']);
- } else {
- $referer = "undefined";
- }
- // request URI
- if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER["HTTP_HOST"])) {
- $request = clean('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
- } else {
- $request = "undefined";
- }
- // query string
- if (isset($_SERVER['QUERY_STRING'])) {
- $string = clean($_SERVER['QUERY_STRING']);
- } else {
- $string = "undefined";
- }
- // IP address
- if (isset($_SERVER['REMOTE_ADDR'])) {
- $address = clean($_SERVER['REMOTE_ADDR']);
- } else {
- $address = "undefined";
- }
- // user agent
- if (isset($_SERVER['HTTP_USER_AGENT'])) {
- $agent = clean($_SERVER['HTTP_USER_AGENT']);
- } else {
- $agent = "undefined";
- }
- // identity
- if (isset($_SERVER['REMOTE_IDENT'])) {
- $remote = clean($_SERVER['REMOTE_IDENT']);
- } else {
- $remote = "undefined";
- }
- // log time
- $time = clean(date("F jS Y, h:ia", time()));
- // sanitize
- function clean($string) {
- $string = rtrim($string);
- $string = ltrim($string);
- $string = htmlentities($string, ENT_QUOTES);
- $string = str_replace("n", "<br>", $string);
- if (get_magic_quotes_gpc()) {
- $string = stripslashes($string);
- }
- return $string;
- }
- $message =
- "TIME: " . $time . "n" .
- "*404: " . $request . "n" .
- "SITE: " . $site . "n" .
- "THEME: " . $theme . "n" .
- "REFERRER: " . $referer . "n" .
- "QUERY STRING: " . $string . "n" .
- "REMOTE ADDRESS: " . $address . "n" .
- "REMOTE IDENTITY: " . $remote . "n" .
- "USER AGENT: " . $agent . "nnn";
- mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email");
- ?>
Tags: WordPress 404错误 管理员
相关文章
- ·WordPress初级教程1:什么是博客?(2013-11-11)
- ·WordPress初级教程-2: 什么是WordPress?(2013-11-11)
- ·WordPress初级教程-3: WordPress的功能和特点(2013-11-11)
- ·WordPress初级教程-4: 选择WordPress博客的主机和域名(2013-11-11)
- ·WordPress初级教程-5: 安装WordPress(2013-11-11)
- ·WordPress初级教程-6: 本地安装WordPress(2013-11-11)
- ·WordPress初级教程-7: 一个数据库中安装多个WordPress博客(2013-11-11)
- ·WordPress初级教程-8: WordPress控制面板/ Dashboard(2013-11-11)
- ·WordPress初级教程-9: WordPress用户设置/ Users(2013-11-11)
- ·WordPress初级教程-10: WordPress博客配置/ Settings(2013-11-11)
- ·关于wordpress上传图片不显示的原因(2013-11-11)
- ·WordPress程序的脆弱点你知道吗 (2013-11-11)
- ·总结八大Wordpress网站百度收录实现秒收的方法绝招 (2013-11-11)
- ·WordPress如何网站投稿者也可以上传图片(2014-03-18)
- ·WordPress怎么修改新用户注册邮件内容(2014-03-18)
- ·WordPress怎么添加前台注册功能(2014-03-18)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)