验证码上中文字是繁体
网上看到个验证码源码,中文的是乱码,刚开始以为是字体问题,换了几个还是一样,不知道为什么
代码如下:
<?php //1.qi启用gd库GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。 // 在网站上GD库通常用来生成缩略图或者用来对图片加水印或者对网站数据生成报表。 session_start(); // 把GBK编码的字符串转换成UTF-8字符串,第一个参数之所以写GBK,是因为本php文件在主机中存储的编码是GBK编码 // UTF-8编码浏览器普遍支持,通用性强,这里就转换成UTF-8 $str = iconv("GBK", "utf-8", "哈哈哈哈哈"); if(!is_string($str) || !mb_check_encoding($str,"utf-8")) { exit("不是字符串或者不是utf-8"); } $zhongwenku_size; // 按UTF-8编码方式获取字符串的长度 $zhongwenku_size = mb_strlen($str,"UTF-8"); // 把上述字符导入数组中 $zhongwenku = array(); for( $i=0; $i<$zhongwenku_size; $i++) { $zhongwenku[$i] = mb_substr($str, $i,1,"UTF-8"); } $result = ""; // 图片上要写入的四个字符 for($i=0; $i<4; $i++) { switch (rand(0, 1)) { case 0: $result.=$zhongwenku[rand(0, $zhongwenku_size-1)]; break; case 1: $result.=dechex(rand(0,15)); break; } } $_SESSION["check"] = $result; // 创建一个真彩图片 宽100,高30 $img = imagecreatetruecolor(100, 30); // 分配背景颜色 $bg = imagecolorallocate($img, 0, 0, 0); // 分配文字颜色 $te = imagecolorallocate($img, 255,255,255); // 在图片上写字符串 //imagestring($img, rand(3,8), rand(1,70), rand(1,10), $result, $te); // 在图片上根据载入字体可以写出特殊字体 imagettftext($img, 13, rand(2, 9), 20 ,20, $te, "msyh.ttf",$result); $_SESSION["check"] = $result; for($i=0; $i<3; $i++) { // $t = imagecolorallocate($img, rand(0, 255),rand(0, 255),rand(0, 255)); // 画线 imageline($img, 0, rand(0, 20), rand(70,100), rand(0, 20), $te); } $t = imagecolorallocate($img, rand(0, 255),rand(0, 255),rand(0, 255)); // 为图片添加噪点 for($i=0; $i<200; $i++) { imagesetpixel($img, rand(1, 100), rand(1, 30), $t); } // 发送http头信息 指定本次发送的是image中的jpeg header("Content-type: image/jpeg"); // 输出jpeg图片至浏览器 imagejpeg($img); ?>
回复讨论(解决方案)
贴出截图看看
微软雅黑是unicode字体么?印象中不是
汗,中文验证码最糟糕了,不但老外不会输入,就算是台湾和香港人也没几个会打简体字的.
用中文验证码其实就是限制只有会打简体字的人能用.
汗,中文验证码最糟糕了,不但老外不会输入,就算是台湾和香港人也没几个会打简体字的.
用中文验证码其实就是限制只有会打简体字的人能用.
现在的验证码都是英文或者数字吧、你这样搞中文,不是限制用户吗?
msyh.ttf 你这个是什么字体呢?
汗,中文验证码最糟糕了,不但老外不会输入,就算是台湾和香港人也没几个会打简体字的.
用中文验证码其实就是限制只有会打简体字的人能用.
现在的验证码都是英文或者数字吧、你这样搞中文,不是限制用户吗?
msyh.ttf 你这个是什么字体呢?
我只是移居到了台?,所以我懂得??中文的拼音.所以我能?入??字.
汗,中文验证码最糟糕了,不但老外不会输入,就算是台湾和香港人也没几个会打简体字的.
用中文验证码其实就是限制只有会打简体字的人能用.
现在的验证码都是英文或者数字吧、你这样搞中文,不是限制用户吗?
msyh.ttf 你这个是什么字体呢?
我只是移居到了台?,所以我懂得??中文的拼音.所以我能?入??字.
难道台湾比大陆好啊。呵呵

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
