网站地图    收藏   

主页 > 后端 > thinkphp教程 >

thinkphp打开验证码页面是乱码 - Thinkphp

来源:自学PHP网    时间:2014-11-28 23:17 作者: 阅读:

[导读] 在用thinkphp开发的时候,有时会出现验证码乱码的问题,解决办法是把如下这个文件放在根目录,访问后就可以解决了,PHP代码如下:?phpif(isset($_GET[ 39;dir 39;])){ 设置文件目录$basedir=$_GET[...

thinkphp打开验证码页面是乱码

在用thinkphp开发的时候,有时会出现验证码乱码的问题,解决办法是把如下这个文件放在根目录,访问后就可以解决了,PHP代码如下:

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

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论