search
HomeBackend DevelopmentPHP Tutorial验证码上中文字是繁体

网上看到个验证码源码,中文的是乱码,刚开始以为是字体问题,换了几个还是一样,不知道为什么
代码如下:

<?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 你这个是什么字体呢?

我只是移居到了台?,所以我懂得??中文的拼音.所以我能?入??字.
难道台湾比大陆好啊。呵呵

Statement
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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software