1 Star 0 Fork 2

dayrui/工具箱

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bom.php 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
dayrui 提交于 2023-09-11 17:26 . 2
<?php
/**
* 文件异常排查
*/
header('Content-Type: text/html; charset=utf-8');
$auto = 1;
define('WEBPATH', dirname(__FILE__).'/');
if (is_file(WEBPATH.'config/database.php')) {
define('ROOTPATH', (dirname(__FILE__)));
} else {
define('ROOTPATH', dirname(dirname(__FILE__)));
}
echo '检查开始:<font color=red>红色字体</font>表示错误问题、<font color=blue>蓝色字体</font>表示轻微<hr>';
checkdir(ROOTPATH);
echo '<hr>检查完毕('.$auto.'),没有出现红色字体的提示就表示一切正常。';
function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..'){
if (!is_dir($basedir."/".$file)) {
if (trim(strtolower(strrchr($file, '.')), '.') == 'php') {
$rt = checkBOM("$basedir/$file");
if ($rt) {
echo "文件:$basedir/$file ".$rt." <br>";
}
}
}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);
$auto++;
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
return ("<font color=red>存在严重问题</font>");
} elseif ($charset[1] != '<') {
return ("<font color=blue>PHP文件不规范</font>");
} else {
return '';
};
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dayrui/tool.git
git@gitee.com:dayrui/tool.git
dayrui
tool
工具箱
master

搜索帮助

Cb406eda 1850385 E526c682 1850385