Home > Backend Development > PHP Tutorial > ThinkPHP solution to the problem of garbled characters when opening the verification code page, thinkphp verification code_PHP tutorial

ThinkPHP solution to the problem of garbled characters when opening the verification code page, thinkphp verification code_PHP tutorial

WBOY
Release: 2016-07-13 10:11:25
Original
1142 people have browsed it

Solution to the problem that ThinkPHP displays garbled codes when opening the verification code page, thinkphp verification code

The example in this article describes the solution to the problem that ThinkPHP displays garbled characters when opening the verification code page. Share it with everyone for your reference. The specific analysis is as follows:

When developing with thinkphp, sometimes the problem of garbled verification codes occurs. The solution is to put the following file in the root directory and access it to solve the problem. The specific PHP code is as follows:

Copy code The code is as follows:
if (isset($_GET['dir'])){ //Set the file directory
$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")."
";
}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 ("BOM found, automatically removed.");
} else {
Return ("BOM found.");
}  
}
else return ("BOM Not Found.");
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

http://www.bkjia.com/PHPjc/929672.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/929672.htmlTechArticleThinkPHP opens the verification code page and displays garbled code. The example of thinkphp verification code in this article tells the example of ThinkPHP opening the verification code page and displaying it. The solution to garbled characters. Share it with everyone for your reference...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template