PHP头条
热点:

thinkphp验证码不现实多半是bom惹的祸


thinkphp 验证码不现实多半是bom惹的祸,下面是驱除bom的代码:

  1. if (isset($_GET['dir'])){ //设置文件目录  
  2. $basedir=$_GET['dir'];  
  3. }else{  
  4. $basedir = '.';  
  5. }  
  6. $auto = 1;  
  7. checkdir($basedir);  
  8. function checkdir($basedir){  
  9. if ($dh = opendir($basedir)) {  
  10.   while (($file = readdir($dh)) !== false) {  
  11.    if ($file != '.' && $file != '..'){  
  12.     if (!is_dir($basedir."/".$file)) {  
  13.      echo "filename: $basedir/$file ".checkBOM("$basedir/$file").
    "
    ;  
  14.     }else{  
  15.      $dirname = $basedir."/".$file;  
  16.      checkdir($dirname);  
  17.     }  
  18.    }  
  19.   }  
  20. closedir($dh);  
  21. }  
  22. }  
  23. function checkBOM ($filename) {  
  24. global $auto;  
  25. $contents = file_get_contents($filename);  
  26. $charset[1] = substr($contents, 0, 1);  
  27. $charset[2] = substr($contents, 1, 1);  
  28. $charset[3] = substr($contents, 2, 1);  
  29. if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {  
  30.   if ($auto == 1) {  
  31.    $rest = substr($contents, 3);  
  32.    rewrite ($filename$rest);  
  33.    return ("BOM found, automatically removed._http://www.phpfensi.com");  
  34.   } else {  
  35.    return ("BOM found.");  
  36.   }  
  37. }  
  38. else return ("BOM Not Found.");  
  39. }  
  40. function rewrite ($filename$data) {  
  41. $filenum = fopen($filename"w");  
  42. flock($filenum, LOCK_EX);  
  43. fwrite($filenum$data);  
  44. fclose($filenum);  
  45. }  
  46. ?>  

www.phpzy.comtrue/phpkj/3046.htmlTechArticlethinkphp验证码不现实多半是bom惹的祸 thinkphp 验证码不现实多半是bom惹的祸,下面是驱除bom的代码: if (isset( $_GET [ dir ])){ //设置文件目录 $basedir = $_GET [ dir ]; } else { $basedir = . ; } $auto =1; che...

相关文章

相关频道:

PHP之友评论

今天推荐