Custom Error Message自定义错误讯息
April 5th, 2007 · by David Bradley 2007年4月5日由大卫布拉德利
Following on from a previous post regarding the以下就从先前的文章就 DON’T PANIC不要惊慌 ethos required of every webmaster when a site goes down, a little revelation regarding the actual problem and an alternative alert for your readers who would otherwise seen an incongruous Wordpress error message.校风所需的每一个网站管理员当网站有云,一点启示有关的实际问题和另一种提高警觉,您的读者,否则谁见过一个格格不入的WordPress错误讯息。
Okay, so there was a database (MySQL) crash at the host for the site in question, which meant all blogging functionality collapsed, as the site hangs on this functionality to render itself it had nowhere to go but to display a little file called wp-db.php This file resides in the Wordpress blog’s wp-includes folder, so here’s what to do to make it more useful to your readers and to modify it so that it sends you an email alert.好了,所以是一个数据库( MySQL的)坠毁在东道国为有问题的网站,这意味着所有的博客功能崩溃,随着该网站的好与坏,此功能,使本身它已无处可去,但显示一个小档案,称为可湿性粉剂- db.php此文件驻留在该WordPress所博客的可湿性粉剂-包括文件夹,所以这里的怎样做,使其更加有用,您的读者和修改,使其向您发送电子邮件警报。
- Make a backup of wp-db.php制作一个备份的可湿性粉剂- db.php
- Make another backup of wp-db.php再作备份可湿性粉剂- db.php
- Unearth the URL of your site’s logo, make sure it’s no wider than about 450 pixels挖掘您网站的网址的标志,确定它没有更广泛的比约450像素
- If you have to create a new logo to comply with this size restriction upload it to your images folder and note the URL如果您要创建一个新的徽标遵守这一尺寸的限制,上传到您的图片文件夹,并记下网址
- Open wp-db.php in your favorite programmer’s text editor, not Notepad or Word开放可湿性粉剂- db.php在您最喜爱的程序员的文本编辑器,而不是记事本或Word
- Scroll to the bottom of the wp-db.php and replace the URL “http://static.wordpress.org/logo.png” with the URL to your logo “http://www.yoursite.com/logo.jpg”.翻阅到底部的可湿性粉剂- db.php和取代的网址“ http://static.wordpress.org/logo.png ”的网址到您的徽标, “ http://www.yoursite.com/logo.jpg “ 。
- Save the wp-db.php file and upload it to your wp-includes folder保存可湿性粉剂- db.php文件,并上传到您的可湿性粉剂-包括文件夹
- Check to see what effect this had by opening the file “http://www.yoursite.com/wp-includes/wp-db.php, you should see your logo, along with a load of text about database and login errors.检查,看看有什么效果,这已开放的档案“ http://www.yoursite.com/wp-includes/wp-db.php ,您应该可以看到您的标志,随着负载的文本数据库和登录错误。
- Next re-open wp-db.php in your text editor and scroll down to the line containing ” function bail($message) { // Just wraps errors in a nice header and footer” or something similar, it’s above a line “if ( !$this->show_errors )” and will be at approximately line 307-335 depending on your installation of Wordpress.明年重新开放可湿性粉剂- db.php在您的文本编辑器和向下滚动,以行“功能保释( $讯息) ( / /刚刚结束的错误好页眉和页脚”或类似的,它的上面一条线“如果( !美元,这” -> s how_errors) “ ,并会在大约线3 07-335取决于您安装的W ordPress。
- Paste the following in between those two lines粘贴以下之间的那些两条线
“/* custom error page hack “ / *自定义错误页面哈克
emails error */电子邮件的错误* /
mail(’your@emailaddress.com’, ‘Sciencebase MySQL Error’, $error);电子邮件( ' your@emailaddress.com ' , ' sciencebase MySQL的错误' ,元,错误) ;
/* end custom error page hack */” / *结束自定义错误页面哈克* / “Editing the dummy email address for your real email address.编辑道具的电子邮件地址为您真实的电子邮件地址。
- Save wp-db.php, upload it once more and check that it is working保存可湿性粉剂- db.php ,上传一次,并检查,这是工作
- Next is an optional step, if you want rid of all those database error remarks and would like to include your own message to your readers then scroll to the section beginning ” $this->bail(”", it’s round about line 50. You can overwrite the gubbins you see there with a personal message and even include links to a mirror site or alternative webs to which you wish to direct your error-stricken visitors. Just remember to use single quote marks in the anchors.明年是可选步骤,如果您想要摆脱所有这些数据库错误的言论,并希望包括您自己的邮件到您的读者,然后滚动到第开始“ $这” ->保释( “ ” ,它的线轮约5 0 。您可以覆盖gubbins你看到有一个个人讯息,甚至包括链接到一个镜像网站或替代网向您想您的错误,直接受灾的旅客,只要记得使用单引号中的基石。
- Save wp-db.php, upload it once more and check that it is working properly保存可湿性粉剂- db.php ,上传一次,并检查它是否工作正常
- Remember, if you upgrade your Wordpress installation, you will have to edit the wp-db.php file again to enable these features.请记住,如果您升级您的WordPress安装过程中,您将不得不修改可湿性粉剂- db.php文件再次启用这些功能。
So, with all that in place, should a MySQL error occur and your site be unable to display its Wordpress components, your readers will not see a nasty default error, but will see your logo and custom error message, and more to the point you will receive an email alerting you to the problem so that you can contact your host’s technical support and get things fixed.因此,所有在的地方,应该一个MySQL错误发生的和您的网站无法显示其在WordPress组件,您的读者将不会看到一个恶劣的默认的错误,但会看到您的徽标和自定义错误消息,并且更多一点,你会收到一封电子邮件,提醒您的问题,让您可以联系您的主机的技术支持和得到的东西,固定的。
There are other more sophisticated methods of overcoming the problem of the default error which provided some inspiration for this post, these can be found at还有其他更复杂的方法,克服的问题,预设的错误,提供了一些启示,为这个职位,这些可以发现在 5thirtyone and和 allforces , to which kudos. ,其中声望。
One additional loose end to tie up, exclude this file from search engine accesses in your robots.txt file (or with a meta noindex) to prevent false positives.一额外的松散年底,以配合起来,排除了这一文件从搜索引擎访问在您的robots.txt文件(或与中继找到Noindex ) ,以防止假阳性。






















1 response so far ↓ 1回应到目前为止↓
David Bradley 大卫布拉德利 // / / Apr 11, 2007 at 9:04 pm 2007年4月11日在下午9点04分
Of course, some of the fixes you may require to get out of trouble with your MySQL, php admin and other stuff aren’t always accessible to you and you simply have to go back to your host to get them to enable a tool or mod that is default disabled.当然,某些修复程序,你可能需要摆脱的麻烦与你的MySQL , PHP的政府当局和其他的东西并不总是方便您和您只需要回去你的主机,让他们使的工具,或按付款当日价格计算这是默认禁用。 Over on sciencebase.com, I didn’t have GET, which meant that the new installation of WP was getting screwed.超过对sciencebase.com ,我没有得到,这意味着该新安装的可湿性粉剂越来越螺纹。 The hostgator people enabled GET and now everything is hunkydory once more.该hostgator人,使得到现在的一切是hunkydory一次。
Leave a Comment留下意见