How to solve the problem of garbled php verification code

藏色散人
Release: 2023-03-07 16:30:02
Original
2539 people have browsed it

Solution to garbled php verification code: 1. Modify the path to access the verification code generation method function; 2. Modify the file encoding and remove the BOM header; 3. Check the verification code generation method; 4. Modify the service environment .

How to solve the problem of garbled php verification code

Recommended: "PHP Video Tutorial"

Specific questions:

php verification code output It’s all gibberish...

<?php
session_start();
header("content-type:image/png"); //设置创建图像的格式
$image_width=70; //设置图像宽度
$image_height=18; //设置图像高度
srand(microtime()*100000); //设置随机数的种子
for($i=0;$i<4;$i++){ //循环输出一个4位的随机数
$new_number.=dechex(rand(0,15));
}
$_SESSION[check_checks]=$new_number; //将获取的随机数验证码写入到SESSION变量中

$num_image=imagecreate($image_width,$image_height); //创建一个画布
imagecolorallocate($num_image,255,255,255); //设置画布的颜色
for($i=0;$i<strlen($_SESSION[check_checks]);$i++){ //循环读取SESSION变量中的验证码
$font=mt_rand(3,5); //设置随机的字体
$x=mt_rand(1,8)+$image_width*$i/4; //设置随机字符所在位置的X坐标
$y=mt_rand(1,$image_height/4); //设置随机字符所在位置的Y坐标
$color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)); //设置字符的颜色
imagestring($num_image,$font,$x,$y,$_SESSION[check_checks][$i],$color); //水平输出字符
}
imagepng($num_image); //生成PNG格式的图像
imagedestroy($num_image); //释放图像资源
?>
Copy after login

Solution:

1. The path to access the verification code generation method/function is incorrect;

2.The file encoding is incorrect, UTF8 encoding does not remove the BOM header;

3. There is a problem with the verification code generation method.

4. The environment does not support it.

The above is the detailed content of How to solve the problem of garbled php verification code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!