/*检测并清除BOM*/
//代码来自网络
//来源:https://www.cnblogs.com/zsl123/p/5980009.html
set_time_limit(0);
if(isset($_GET["dir"])){
$basedir=$_GET["dir"];
}else{
$basedir = ".";
}
$auto = 1;
checkdir($basedir);
$count=0;
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);
}
}
}//end while
closedir($dh);
}//end if($dh
}//end function
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.");
}//end function
function rewrite($filename, $data){
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}//end function
?>
运行完毕后即可清除bom头,然后网站就恢复正常了。
找到根目录下的includes文件夹,然后打开init.php文件,注释掉session_start()这行,在前面加@即可。
有时候这样的报错也是因为文件的bom头问题,可以复制下列代码,新建一个“bom.php”文件,运行即可
/*检测并清除BOM*/
//代码来自网络
//来源:https://www.cnblogs.com/zsl123/p/5980009.html
set_time_limit(0);
if(isset($_GET["dir"])){
$basedir=$_GET["dir"];
}else{
$basedir = ".";
}
$auto = 1;
checkdir($basedir);
$count=0;
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);
}
}
}//end while
closedir($dh);
}//end if($dh
}//end function
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.");
}//end function
function rewrite($filename, $data){
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}//end function
?>
运行完毕后即可清除bom头,然后网站就恢复正常了。
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快
上一篇:无法向会话状态服务器发出会话状态请求。请确保 ASP.NET State Service (ASP.NET 状态服务)已启动 下一篇:如何清除dns缓存?清除dns缓存命令方法