在前几天看访问的原始日志的时候,突然发现很多错误记录,后来发现问题出在主题文件夹下的index.php文件,如果直接访问https://onedou.com/wp-content/themes/will/index.php则会出现“Fatal error: Call to undefined function get_header()”,如图:
而get_header()这个函数是WordPress系统函数,不可能没有定义这个函数,而是加载index.php的时候没有引入该函数,所以造成了该问题的出现。
如果自己有设置主机php.ini的权限,不操心log的话,可以修改如下,就不会有错误提示了:
1 2 | display_errors = off error_reporting=E_ALL&~E_NOTICE |
因为没有权限懂php.ini,于是,我在index.php中添加不显示运行错误:
<?php ini_set('display_errors', 0); ?> |
这样以后就没有了错误提示,可是error-log中依旧记录着该错误,如何不记录这个错误呢?如果直接加载index.php且没有定义get_header()这个函数,就直接重定向到网站首页,所以一个简单地判断就可以搞定了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php ini_set('display_errors', 0); ?> <?php /* @FileName:index.php @Aurthor: OneDou [http://oneodu.com] @LastModifed:2013-6-10 下午11:27:33 @Charset:UTF-8 */ if (function_exists('get_header')) { get_header(); }else{ header("Location: http://" . $_SERVER['HTTP_HOST'] . ""); exit; }; ?> |
Ok,这样如果直接访问index.php就被重定向到了首页,而且error-log中就清爽多了。
我的也有这个问题
感谢!