国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > DedeCMS > PHPCMS后台白屏的完美解决方法

PHPCMS后台白屏的完美解决方法

来源:程序员人生   发布时间:2014-01-06 00:58:23 阅读次数:3549次

  前一段时间一直受后台白屏和网页显示异常的困扰,发现主要是文件编码的问题,不仅是UTF和GBK的问题,如果UTF编码文件多出个BOM也会造成很多不可知的问题。如我前段时间提的灵异现象,今天终于解决了。为了帮助更多朋友解决这个问题,特发一个从网上找的小文件,大家也可以试试,不保行哦。

  使用方法是:把以下代码复制到记事本,保存为liehuo.php,然后传到你认为编码有问题的目录下,运行之。作用是:去除所有UTF-8编码文件的BOM。(注意:用之前别忘了备份。)  

以下为引用的内容:
<?php

//remove the utf-8 boms
//by magicbug at gmail dot com

if (isset($_GET['dir'])){ //config the basedir
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}

$auto = 1;

checkdir($basedir);

function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..'){
if (!is_dir($basedir."/".$file)) {
echo "filename: $basedir/$file ".checkBOM("$basedir/$file")."
";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}

function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return ("BOM found, automatically removed.");
} else {
return ("BOM found.");
}
}
else return ("BOM Not Found.");
}

function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}  //liehuo.net

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生