解决php验证码不显示问题,解决php7/php8的验证码不显示情况

by 少年2021-07-20
  • 1 赞
  • 1 收藏
  • 技术
  • 19990 评论
  • 74603 阅读
© 本文 by 少年 版权所有,作者未对本笔记声明转载限制,转载时请注明本文标题和链接。
笔记

php建站经常会遇到验证码不显示的情况,特别是php网站程序搬移服务器或者更换主机时经常会遇到,可能你已经在网上找了很多方法,按着做了一遍还是不显示,那你就需要用到本笔记的一些内容了。废话不多说,先把网上得解决方法的整理一下:


1、未安装或未开启gd模块


出现验证码不显示的情况,最基本的一个错误就是你很可能在php里面忘记安装gd模块了。window环境下面只需要在php.ini文件里面找到,注意不同版本的php配置项是有区别的,如下:

;extension=php_gd2.dll      ### PHP 5.* 版本
;extension=gd2              ### PHP 7.* 版本
;extension=gd ### PHP 8.* 版本

把前面的分号去掉就可以了,重启apache后,你就可以在phpinfo()里面找到这个

如果是在ubuntu等linux环境下面,你需要安装gd模块


2、文档使用了有BOM的编码格式


如果你的gd库安装并开启了,任然不显示验证码,那就可能是你的生成文档可能采用了有BOM的utf-8。


UTF-8 BOM又叫UTF-8 签名,其实UTF-8 的BOM对UFT-8没有作用,是为了支持UTF-16、UTF-32才加上的BOM,BOM签名的意思就是告诉编辑器当前文件采用何种编码,方便编辑器识别,但是BOM虽然在编辑器中不显示,但是会产生输出,就像多了一个空行(一般是三个字节)。session_start();开启前是不能有输出的,而这个UTF-8 BOM产生输出是在文档最上方,所以会导致出错。


这时采用无BOM的UTF-8格式就可以解决问题,所以你需要将代码的编码格式改成无BOM格式。采用编辑器修改下编码格式即可。


除了修改编码格式,你还可以采用另外的一种方法,那就是在代码 session_start(); 前加上 ob_clean(); 即可解决BOM签名带来的问题。


<?php
ob_clean();
session_start();
....


什么?你说你上边的方法你都做了,验证码还不显示,好吧,这种问题我也遇到了,你的新环境版本是不是PHP7.*?是的话,那么你就来对地方了。


3、填充内容函数imagettftext()参数和php版本问题


问题是出现在笔者安装了多个php版本环境进行程序兼容测试中,测试的php版本包括PHP5.*的几个版本,PHP7.*的几个版本和PHP8.*的几个版本,测试发现PHP5.*和PHP8.*下能正常显示验证码,而在PHP7.*的全系列版本都不能正常显示,经对代码分析发现原因是我采用了imagettftext()函数填充内容到到验证码的画布中,如果采用imagestring()函数填充内容就能正常显示。


解决方法你可以改用imagestring()来代替imagettftext()函数,但是如果仍然想要使用imagettftext()来自定义填充内容的字体样式的话,往下看。


经查询手册发现验证码不显示是由于imagettftext()函数的字体路径引起的,我之前使用了字体文件是相对路径"font/fenix.ttf",这种写法,php5.X和php8.X支持,但是php7.X需要是使用绝度路径,即使用'D:/www/core/font/fenix.ttf'这种形式,经测试采用网络形式的加载也是可行的"https://www.ideashu.cn/core/font/fenix.ttf",为了兼容此处改用绝对路径即可完美解决问题。


代码如下(代码是在项目中使用的,有些是项目中定义好的常量和变量,切勿直接复制使用):


//imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);// 填充内容到画布中
$fonturl=IDEA_ROOT .'/core/font/fenix.ttf';//php5.X和php8.X支持相对路径font/fenix.ttf,但是php7.X需要使用绝对路径,为了兼容此改该用绝对路径
imagettftext($image,$fontsize,0,$x,$y,$fontcolor,$fonturl,$fontcontent);


谢谢你的阅读,希望能够帮到你。


---

评论
ixuqozy
Doppler fpo.sxoq.ideashu.cn.ilo.gs any, [URL=http://damcf.org/item/buy-prednisone-online-canada/ - order prednisone 5[/URL - [URL=http://livinlifepc.com/generic-flagyl-from-india/ - generic flagyl from india[/URL - [URL=http://telugustoday.com/product/diclofenac/ - diclofenac for sale overnight[/URL - [URL=http://buckeyejeeps.com/buy-amoxicillin-on-line/ - amoxicillin[/URL - [URL=http://mrcpromotions.com/drug/tretinoin-canada/ - tretinoin canada[/URL - [URL=http://anguillacayseniorliving.com/item/ordering-prednisone/ - comprar prednisone en usa[/URL - [URL=http://healinghorsessanctuary.com/chloromycetin/ - discount chloromycetin[/URL - [URL=http://livinlifepc.com/flagyl/ - flagyl capsules[/URL - [URL=http://creativejamaicans.com/viagra-professional/ - purchase viagra professional[/URL - [URL=http://damcf.org/item/prednisone-lowest-price/ - prednisone[/URL - [URL=http://heavenlyhappyhour.com/tadalafil-best-price-usa/ - tadalafil[/URL - [URL=http://rozariatrust.net/hydroquin-buy/ - hydroquin[/URL - [URL=http://otrmatters.com/hydroxychloroquine-original/ - hydroxychloroquine[/URL - [URL=http://eatingaftergastricbypass.net/prednisolone/ - prednisolone[/URL - [URL=http://ossoccer.org/v-tada/ - v tada to buy[/URL - acetabulum spleen prednisone 10 mg price australia on line flagyl diclofenac for sale overnight cheap amoxicillin online tretinoin canada prednisone francais chloromycetin flagyl viagra professional generic viagra professional prednisone tadalafil hydroquin cheap hydroxychloroquine alternative buy prednisolone on line v tada to buy bulla, http://damcf.org/item/buy-prednisone-online-canada/ buy prednisone online canada http://livinlifepc.com/generic-flagyl-from-india/ flagyl buy in canada http://telugustoday.com/product/diclofenac/ diclofenac lowest price http://buckeyejeeps.com/buy-amoxicillin-on-line/ amoxicillin en ligne http://mrcpromotions.com/drug/tretinoin-canada/ buy tretinoin http://anguillacayseniorliving.com/item/ordering-prednisone/ prednisone online no doctor prescription http://healinghorsessanctuary.com/chloromycetin/ chloromycetin online http://livinlifepc.com/flagyl/ flagyl http://creativejamaicans.com/viagra-professional/ viagra professional sublingual viagra professional tablets cost http://damcf.org/item/prednisone-lowest-price/ prednisone online uk buy prednisone online canada http://heavenlyhappyhour.com/tadalafil-best-price-usa/ tadalafil best price usa http://rozariatrust.net/hydroquin-buy/ generic hydroquin online http://otrmatters.com/hydroxychloroquine-original/ can buy real hydroxychloroquine online http://eatingaftergastricbypass.net/prednisolone/ prednisolone nextday http://ossoccer.org/v-tada/ v tada capsules for sale edges severity pupil.

2021-12-08 18:14:59回复

nqeviffe
Birth wen.fwbb.ideashu.cn.xqy.jy flushing, reasoning urgency discount tadalista buy misoprostol prednisone viagra professional generic generic levitra extra dosage uk viagra superactive canadian no prescription ginette-35 2mg from usa viagra 50 mg from canadian pharmacy cheap virility-patch-rx cialis black pill generic zoloft canadian pharmacy no prescription retin a no prescription amoxil average cost of fildena 100mg hydroxychloroquine buy online be, intercourse, order tadalista online buy tadalista cytotec cytotec prednisone 20 mg in canada viagra professional tablets cost overnight levitra extra dosage cheap generic buy viagra buy ginette-35 w not prescription viagra without pres virility-patch-rx lowest price cialis black for sale zoloft retin a amoxil information cost wallmart fildena hydroxychloroquine endocervical commoner family http://thesteki.com/tadalista/ buy tadalista http://columbiainnastoria.com/cytotec/ cytotec http://anguillacayseniorliving.com/drugs/order-prednisone-dozirovkamg-online/ prednisone shopping http://creativejamaicans.com/viagra-professional/ viagra professional generic viagra professional http://memoiselle.com/item/levitra-extra-dosage/ buy levitra extra dosage no prescription http://brisbaneandbeyond.com/viagra-superactive-canadian-no-prescription/ viagra 25 mg india http://washingtonsharedparenting.com/ginette-35/ ginette-35 information http://rozariatrust.net/viagra-without-pres/ buying viagra from india http://iowansforsafeaccess.org/virility-patch-rx/ virility-patch-rx http://thesteki.com/cialis-black/ cialis black http://solepost.com/zoloft-nasal-inhaler/ generic zoloft cost http://heavenlyhappyhour.com/retin-a-from-canada/ retin a non generic http://mrcpromotions.com/drug/prices-for-amoxil/ buy amoxil online cheap http://anguillacayseniorliving.com/drugs/fildena/ fildena http://columbiainnastoria.com/low-cost-hydroxychloroquine/ buy hydroxychloroquine hydroxychloroquine pectoralis liver.

2021-12-08 18:05:56回复

uwoyupunoweu
Sustainability xxz.esjm.ideashu.cn.hop.fg pipes, pulsus curvature; [URL=http://thegrizzlygrowler.com/levitra-buy/ - non prescription levitra[/URL - [URL=http://djmanly.com/product/digoxin/ - digoxin in italien[/URL - [URL=http://americanartgalleryandgifts.com/cialis-oral-jelly-online/ - buy cialis oral jelly[/URL - [URL=http://mannycartoon.com/deltasone-for-sale/ - prednisonewithoutprescription[/URL - [URL=http://rozariatrust.net/doxycycline/ - doxycycline 200 mg g[/URL - doxycycline granada [URL=http://otrmatters.com/item/cialis/ - cialis[/URL - [URL=http://gnlg.org/item/cialis/ - 10 mg cialis pills[/URL - [URL=http://heavenlyhappyhour.com/tadalafil-best-price-usa/ - mail order tadalafil prescriptions[/URL - [URL=http://mrcpromotions.com/drug/priligy-generic-pills/ - priligy[/URL - [URL=http://scoverage.org/lasix-for-sale/ - lasix commercial[/URL - [URL=http://anguillacayseniorliving.com/drugs/order-prednisone-dozirovkamg-online/ - prednisone no prescription online cheap[/URL - prednisone tablets for sale [URL=http://creativejamaicans.com/serevent/ - serevent generic[/URL - [URL=http://eatingaftergastricbypass.net/elinal/ - lowest price generic elinal[/URL - [URL=http://umichicago.com/cipro/ - buy cipro online[/URL - ciprofloxacin hcl 500mg [URL=http://washingtonsharedparenting.com/bactrim/ - bactrim coupons[/URL - bactrim generic warn non prescription levitra on line digoxin purchase buy cialis oral jelly online deltasone for sale buy doxycycline phuket generic cialis 5 mg daily canadian cialis 5 mg generico online find tadalafil without prescription generic priligy 90 mg tablets lasix for sale prednisone online serevent non prescription elinal buy cipro online buy cipro online bactrim without a doctor implications innervate http://thegrizzlygrowler.com/levitra-buy/ levitra http://djmanly.com/product/digoxin/ comprare digoxin http://americanartgalleryandgifts.com/cialis-oral-jelly-online/ cialis oral jelly online buy cialis oral jelly http://mannycartoon.com/deltasone-for-sale/ 5mg prednisone for dogs no prescription http://rozariatrust.net/doxycycline/ purchase doxycycline without a prescription http://otrmatters.com/item/cialis/ cialis http://gnlg.org/item/cialis/ cialis 10 mg herbal http://heavenlyhappyhour.com/tadalafil-best-price-usa/ buy tadalafil online in prices for tadalafil http://mrcpromotions.com/drug/priligy-generic-pills/ priligy http://scoverage.org/lasix-for-sale/ lasix http://anguillacayseniorliving.com/drugs/order-prednisone-dozirovkamg-online/ online prednisone purchase in india http://creativejamaicans.com/serevent/ serevent for sale http://eatingaftergastricbypass.net/elinal/ elinal http://umichicago.com/cipro/ ciprofloxacin hcl 500mg http://washingtonsharedparenting.com/bactrim/ bactrim hand-washing foul-smelling injection.

2021-12-08 18:02:10回复

asosupu
Radiographs gau.scte.ideashu.cn.paa.xf photoreceptor deceased dead [URL=http://themusicianschoice.net/cialis-black/ - xmlppc cialis black[/URL - [URL=http://heavenlyhappyhour.com/item/celebrex/ - celebrex pills[/URL - celebrex tablets [URL=http://kafelnikov.net/aciclovir/ - aciclovir[/URL - [URL=http://gnlg.org/product/synthroid/ - synthroid.com lowest price[/URL - [URL=http://redlightcameraticket.net/item/hydrocl/ - hydrocl[/URL - [URL=http://davincipictures.com/fildena-super-active/ - fildena super active[/URL - [URL=http://umichicago.com/doxt-sl/ - doxt sl[/URL - cheap doxt sl online [URL=http://livinlifepc.com/levitra-buy-online/ - discount levitra fast shipping[/URL - [URL=http://otrmatters.com/hydroxychloroquine-original/ - hydroxychloroquine[/URL - [URL=http://cgodirek.com/altace/ - altace[/URL - [URL=http://gasmaskedlestat.com/item/prednisone-20mg-side-effects/ - prednisone no prescription cod[/URL - [URL=http://ossoccer.org/drugs/sildalis/ - sildalis[/URL - [URL=http://washingtonsharedparenting.com/diflucan/ - generic diflucan lowest price[/URL - [URL=http://thesteki.com/glucophage/ - glucophage online[/URL - [URL=http://gnlg.org/product/levitra/ - levitra[/URL - upper, low-fibre interstitial cialis black buying celebrex generic aciclovir synthroid synthroid non generic hydrocl fildena super active buy doxt sl w not prescription buying doxt sl levitra hydroxychloroquine original cheap altace prednisone for dog sildalis on internet diflucan without prescription buy glucophage order glucophage online generic levitra online conceptual contentious http://themusicianschoice.net/cialis-black/ cialis black for sale http://heavenlyhappyhour.com/item/celebrex/ buying celebrex http://kafelnikov.net/aciclovir/ cheap aciclovir aciclovir lowest price http://gnlg.org/product/synthroid/ synthroid best price usa http://redlightcameraticket.net/item/hydrocl/ hydrocl canadian pharmacy http://davincipictures.com/fildena-super-active/ fildena super active price walmart http://umichicago.com/doxt-sl/ generic doxt sl in canada http://livinlifepc.com/levitra-buy-online/ achat levitra internet http://otrmatters.com/hydroxychloroquine-original/ online meds hydroxychloroquine http://cgodirek.com/altace/ altace lowest price altace http://gasmaskedlestat.com/item/prednisone-20mg-side-effects/ buy prednisone online in us http://ossoccer.org/drugs/sildalis/ www.sildalis.com http://washingtonsharedparenting.com/diflucan/ generic diflucan lowest price http://thesteki.com/glucophage/ discount glucophage glucophage online http://gnlg.org/product/levitra/ online levitra no prescription weeks dehydration.

2021-12-08 18:00:14回复

urokyov
Approximately rbg.aqdt.ideashu.cn.vga.jv paediatrics, seductively [URL=http://damcf.org/lamictal/ - lamictal online pharmacy[/URL - [URL=http://columbiainnastoria.com/buy-amoxicillin-no-prescription/ - buy amoxicillin no prescription[/URL - [URL=http://gnlg.org/item/cialis-commercial/ - cialis uk[/URL - [URL=http://rozariatrust.net/tadalafil/ - tadalafil[/URL - [URL=http://anguillacayseniorliving.com/drugs/flomax/ - buy cheap flomax fast free shipping[/URL - [URL=http://anguillacayseniorliving.com/prednisone-generic-pills/ - generic prednisone lowest price[/URL - [URL=http://healthkosh.com/propecia/ - propecia without prescription[/URL - [URL=http://washingtonsharedparenting.com/diflucan/ - diflucan[/URL - [URL=http://kafelnikov.net/ventolin/ - buy ventolin online[/URL - [URL=http://gnlg.org/item/viagra/ - 75mg viagra lowest price[/URL - [URL=http://columbiainnastoria.com/vidalista/ - vidalista[/URL - [URL=http://aawaaart.com/extra-super-tadarise/ - extra super tadarise[/URL - [URL=http://damcf.org/item/flomax/ - mail order flomax prescriptions[/URL - [URL=http://mrcpromotions.com/drug/generic-flagyl-from-india/ - web pharmacy flagyl 200[/URL - flagyl [URL=http://washingtonsharedparenting.com/pharmacy-on-line/ - generic pharmacy tablets[/URL - retains lamictal from india amoxil 250 mg. cheapest generic cialis 20 mg tadalafil on line where can i buy generic flomax online cheap flomax prices generic prednisone canada pharmacy propecia without prescription generic diflucan lowest price ventolin generic viagra online usa master card vidalista without an rx generic extra super tadarise uk where can i get flomax cheaper flagyl pharmacy cheap chemotherapy, http://damcf.org/lamictal/ lamictal generic pills http://columbiainnastoria.com/buy-amoxicillin-no-prescription/ online generic amoxicillin amoxil 650 mg cost http://gnlg.org/item/cialis-commercial/ cialis in augsburg http://rozariatrust.net/tadalafil/ tadalafil http://anguillacayseniorliving.com/drugs/flomax/ flomax http://anguillacayseniorliving.com/prednisone-generic-pills/ generic prednisone canada pharmacy http://healthkosh.com/propecia/ propecia without prescription http://washingtonsharedparenting.com/diflucan/ diflucan http://kafelnikov.net/ventolin/ ventolin http://gnlg.org/item/viagra/ viagra http://columbiainnastoria.com/vidalista/ cheap vidalista http://aawaaart.com/extra-super-tadarise/ extra super tadarise generic canada online extra super tadarise no prescription http://damcf.org/item/flomax/ get 0.4 flomax http://mrcpromotions.com/drug/generic-flagyl-from-india/ web pharmacy flagyl 200 http://washingtonsharedparenting.com/pharmacy-on-line/ generic pharmacy tablets exceptional lymphadeno-pathy, anaemic.

2021-12-08 17:57:52回复

12345678 ... 3998(有 19990 条评论)