本文实例讲述了WordPress站点呈现404谬误时邮件告诉治理员的办法。分享给大家供大家参考。详细剖析如下:
这是一个比拟适用的性能,当咱们网站呈现了谬误时就邮箱告诉治理员,将上面的代码增加到你所用的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", "
", $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");
?>
心愿本文所述对大家的WordPress建站有所协助。
以上就是安达网络工作室关于《WordPress站点出现404错误时邮件通知管理员的方法》的一些看法。更多内容请查看本栏目更多内容!
WordPress能够经过一系列的工夫日期函数来管制工夫日期的输入,上面引见几个罕用的函数:1、the_date_xml()...
复制代码代码如下: <?php $epaged = (get_query_var('paged')) ? get_query_var('paged') : 1; $temp = $wp...
由于偶然加一些站外链接,普通都是nofollow,独自写入很费事,所以揣摩从编辑器动手,经过这个插件(http:/...
次要出于两个目的,第一搜集比便大家和当前学习回顾;第二,从根底做一些适用的,添加搜寻量,进步博客流量...
本文实例讲述了Wordpress主动提取内容中第一张图片作缩略图的办法。分享给大家供大家参考。详细剖析如下: ...
家喻户晓,wordpress是基于php开发,在apache效劳下运转是最优秀的。然而,国际依然有很多主机上不能提供ap...