使用織夢(mèng)dede也很長(zhǎng)一段時(shí)間了,可是今天遇到一個(gè)問(wèn)題就是驗(yàn)證碼不顯示,我網(wǎng)上找了很多資料,幾乎全都是說(shuō)權(quán)限和GD庫(kù)的問(wèn)題。
可是按照這些方法試過(guò)后,驗(yàn)證碼仍然不能顯示。
后來(lái)想到以前做網(wǎng)站的時(shí)候遇到一個(gè)UTF-8編碼的BOM問(wèn)題。于是就去網(wǎng)上找了段代碼,去掉了整個(gè)網(wǎng)站文件的BOM。 去掉后驗(yàn)證碼還真顯示了。
試分析了一下原因,可能是因?yàn)锽OM會(huì)產(chǎn)生一個(gè)空行的輸出。導(dǎo)致生成驗(yàn)證碼的時(shí)候會(huì)產(chǎn)生錯(cuò)誤,所以不能顯示。
批量去除BOM的方法:將以下代碼保存為PHP文件,通過(guò)瀏覽器進(jìn)行訪問(wèn)即可。
<?php
//remove the utf-8 boms
//by magicbug at gmail dot com
if (isset($_GET['dir'])){ //要去除的文件目錄,無(wú)參數(shù)則為文件當(dāng)前目錄。
$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”).” <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);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 &&
ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return (“<font color=red>BOM found,
automatically removed.</font>”);
} else {
return (“<font color=red>BOM found.
</font>”);
}
}
else return (“BOM Not Found.”);
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, “w”);
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>
?
可是按照這些方法試過(guò)后,驗(yàn)證碼仍然不能顯示。
后來(lái)想到以前做網(wǎng)站的時(shí)候遇到一個(gè)UTF-8編碼的BOM問(wèn)題。于是就去網(wǎng)上找了段代碼,去掉了整個(gè)網(wǎng)站文件的BOM。 去掉后驗(yàn)證碼還真顯示了。
試分析了一下原因,可能是因?yàn)锽OM會(huì)產(chǎn)生一個(gè)空行的輸出。導(dǎo)致生成驗(yàn)證碼的時(shí)候會(huì)產(chǎn)生錯(cuò)誤,所以不能顯示。
批量去除BOM的方法:將以下代碼保存為PHP文件,通過(guò)瀏覽器進(jìn)行訪問(wèn)即可。
<?php
//remove the utf-8 boms
//by magicbug at gmail dot com
if (isset($_GET['dir'])){ //要去除的文件目錄,無(wú)參數(shù)則為文件當(dāng)前目錄。
$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”).” <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);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 &&
ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return (“<font color=red>BOM found,
automatically removed.</font>”);
} else {
return (“<font color=red>BOM found.
</font>”);
}
}
else return (“BOM Not Found.”);
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, “w”);
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>
?

步驚云