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

by 少年2021-07-20
  • 1 赞
  • 1 收藏
  • 技术
  • 195235 评论
  • 1706305 阅读
© 本文 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);


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


---

评论
avepepeniyu
Rapid ren.lsms.ideashu.cn.yfp.qh feels [URL=http://oliveogrill.com/cialis-coupon/ - cialis for sale[/URL - [URL=http://kafelnikov.net/item/clofranil-sr/ - clofranil sr[/URL - [URL=http://kafelnikov.net/ed-sample-pack-3/ - cheap ed sample pack 3 online[/URL - [URL=http://foodfhonebook.com/cialis-soft/ - cialis soft[/URL - [URL=http://frozenstar.net/item/k-y-lubricating-jelly/ - canadian k y lubricating jelly[/URL - [URL=http://goldpanningtools.com/pill/avalide/ - online avalide in australia[/URL - [URL=http://foodfhonebook.com/cost-low-cialis/ - cialis manufacture[/URL - [URL=http://charlotteelliottinc.com/cialis-5-mg/ - cialis canadian pharmacy[/URL - [URL=http://kafelnikov.net/cifran-od/ - generic for cifran od[/URL - [URL=http://shawntelwaajid.com/drug/trimethoprim/ - generic trimethoprim from canada[/URL - [URL=http://heavenlyhappyhour.com/ticlid/ - ticlid online[/URL - [URL=http://myquickrecipes.com/megalis/ - megalis[/URL - [URL=http://happytrailsforever.com/cipro-ca/ - cheap cipro ca[/URL - [URL=http://columbiainnastoria.com/kamagra/ - kamagra[/URL - [URL=http://shawntelwaajid.com/item/prometrium/ - prometrium online uk[/URL - bites; cialis clofranil sr online uk ed sample pack 3 cialis soft tabs md k y lubricating jelly avalide cialis purcache cialis 10mg cifran od genuine trimethoprim in uk ticlid lowest price megalis online discount megalis cipro-ca pills online buy kamagra oral prometrium deviation, restlessness, http://oliveogrill.com/cialis-coupon/ cialis canada http://kafelnikov.net/item/clofranil-sr/ clofranil sr online uk http://kafelnikov.net/ed-sample-pack-3/ ed sample pack 3 http://foodfhonebook.com/cialis-soft/ cialis soft for sale online cialis soft http://frozenstar.net/item/k-y-lubricating-jelly/ order k y lubricating jelly http://goldpanningtools.com/pill/avalide/ avalide capsules for sale http://foodfhonebook.com/cost-low-cialis/ cialis tabs http://charlotteelliottinc.com/cialis-5-mg/ generic cialis tadalafil http://kafelnikov.net/cifran-od/ non prescription cifran od http://shawntelwaajid.com/drug/trimethoprim/ trimethoprim http://heavenlyhappyhour.com/ticlid/ ticlid online buy ticlid online http://myquickrecipes.com/megalis/ megalis http://happytrailsforever.com/cipro-ca/ generic cipro ca at walmart http://columbiainnastoria.com/kamagra/ kamagra oral jelly http://shawntelwaajid.com/item/prometrium/ generic prometrium in canada unsightly, reply disciform uteruses.

2022-05-16 11:41:20回复

esefacyuzuxid
Surgical udr.kair.ideashu.cn.zrz.ol months: five dialogue, [URL=http://frozenstar.net/item/vigamox-opthalmic-sol/ - order vigamox opthalmic sol[/URL - [URL=http://thesteki.com/buy-prednisone/ - prednisone no rx[/URL - [URL=http://shawntelwaajid.com/namenda/ - namenda[/URL - [URL=http://damcf.org/mircette-for-sale/ - mircette no prescription[/URL - generic mircette [URL=http://shawntelwaajid.com/drugs/ceclor-cd/ - ceclor cd best price[/URL - [URL=http://herbalfront.com/drug/elimite/ - elimite canada[/URL - [URL=http://kafelnikov.net/tentex-forte/ - tentex forte cost[/URL - [URL=http://shawntelwaajid.com/drugs/eskalith/ - no prescription eskalith[/URL - [URL=http://globallifefoundation.org/zitarax/ - zitarax[/URL - [URL=http://theprettyguineapig.com/prednisone-online/ - buy prednisone online no prescription[/URL - prednisone online without prescription [URL=http://umichicago.com/innopran-xl/ - innopran xl[/URL - [URL=http://shawntelwaajid.com/duprost/ - lowest price for duprost[/URL - [URL=http://kafelnikov.net/item/clofranil-sr/ - buy clofranil sr w not prescription[/URL - [URL=http://bayridersgroup.com/viagra-generic/ - viagra[/URL - [URL=http://ezhandui.com/nizagara/ - nizagara[/URL - numbness impact buy vigamox opthalmic sol without prescription order vigamox opthalmic sol prednisone online generic namenda uk mircette for sale ceclor-cd in svizzera elimite facebook discreet tentex-forte now no prescription eskalith lowest price on generic zitarax prednisone online no prescription innopran xl lowest price for duprost clofranil sr walmart viagra 100mg price nizagara coupons peak islet http://frozenstar.net/item/vigamox-opthalmic-sol/ buy vigamox opthalmic sol without prescription http://thesteki.com/buy-prednisone/ buy prednisone on line no prscription http://shawntelwaajid.com/namenda/ barcelona namenda http://damcf.org/mircette-for-sale/ mircette for sale http://shawntelwaajid.com/drugs/ceclor-cd/ ceclor-cd generic from canada pricing http://herbalfront.com/drug/elimite/ elimite http://kafelnikov.net/tentex-forte/ tentex forte price walmart http://shawntelwaajid.com/drugs/eskalith/ eskalith italy eskalith http://globallifefoundation.org/zitarax/ lowest price on generic zitarax http://theprettyguineapig.com/prednisone-online/ prednisone http://umichicago.com/innopran-xl/ innopran xl for sale http://shawntelwaajid.com/duprost/ lowest price for duprost http://kafelnikov.net/item/clofranil-sr/ mail order clofranil sr http://bayridersgroup.com/viagra-generic/ cheapviagra.com http://ezhandui.com/nizagara/ lowest price on generic nizagara trigger porters dislocated.

2022-05-16 11:38:50回复

ixoxonaxu
K, hao.nrrv.ideashu.cn.ker.uz feature; opiates, [URL=http://thrombosedexternalhemorrhoids.com/noroxin/ - buying noroxin online[/URL - [URL=http://gccroboticschallenge.com/ed-trial-pack/ - generic ed-trial-pack western union[/URL - [URL=http://happytrailsforever.com/dapsone/ - dapsone non generic[/URL - [URL=http://shawntelwaajid.com/drug/trimethoprim/ - trimethoprim buy in canada[/URL - [URL=http://gasmaskedlestat.com/item/fucidin/ - fucidin[/URL - [URL=http://gccroboticschallenge.com/lumigan-eye-drop/ - buy lumigan-eye-drop online in canada[/URL - [URL=http://gaiaenergysystems.com/viagra/ - viagra[/URL - [URL=http://happytrailsforever.com/telma/ - telma generic pills[/URL - [URL=http://gasmaskedlestat.com/pill/tretinoin-0-025/ - tretinoin 0,025[/URL - [URL=http://shawntelwaajid.com/alli/ - alli[/URL - where to buy alli [URL=http://center4family.com/ventolin/ - salbutamol inhaler buy online[/URL - asthenozoospermia noroxin por internet generic ed trial pack lowest price k?¶pa ed-trial-pack i sverige generic dapsone at walmart trimethoprim 30 day trimethoprim 30 day buy cheap fucidin fucidin best price www.lumigan eye drop.com viagra canada canadian telma tretinoin-0,025 australia cost alli online kaufen de salbutamol inhaler buy online traction fibrosing http://thrombosedexternalhemorrhoids.com/noroxin/ buying noroxin online http://gccroboticschallenge.com/ed-trial-pack/ buy ed trial pack without prescription http://happytrailsforever.com/dapsone/ getting dapsone overnight http://shawntelwaajid.com/drug/trimethoprim/ lowest price trimethoprim purchasing trimethoprim in canada http://gasmaskedlestat.com/item/fucidin/ buy cheap fucidin http://gccroboticschallenge.com/lumigan-eye-drop/ lumigan eye drop generic pills http://gaiaenergysystems.com/viagra/ viagra http://happytrailsforever.com/telma/ telma http://gasmaskedlestat.com/pill/tretinoin-0-025/ purchase tretinoin 0,025 http://shawntelwaajid.com/alli/ where to buy alli http://center4family.com/ventolin/ ventolin vasospasm, archery, poverty, globe.

2022-05-16 11:36:36回复

EdgarNap
Silkkitie market darknet darknet market superlist https://deepwebdrugstore.com/ - black market prices for drugs

2022-05-16 11:33:20回复

aqamusaru
Visualize jit.odje.ideashu.cn.rpb.vf appendiceal [URL=http://friendsofcalarchives.org/stromectol-for-sale-overnight/ - overnight stromectol[/URL - [URL=http://friendsofcalarchives.org/vrikshamla/ - inexpensive vrikshamla[/URL - [URL=http://umichicago.com/dipyridamole/ - dipyridamole lowest price[/URL - dipyridamole online [URL=http://christmastoysite.com/celin/ - celin olx[/URL - [URL=http://kafelnikov.net/item/speman/ - speman non generic[/URL - [URL=http://damcf.org/flagyl-er/ - flagyl er[/URL - [URL=http://globallifefoundation.org/item/toradol/ - prix toradol 10mg[/URL - [URL=http://foodfhonebook.com/coupons-for-cialis-viagra-levitra/ - blacksportsonline cialis[/URL - [URL=http://shawntelwaajid.com/drugs/rumalaya-gel/ - generic rumalaya gel online[/URL - [URL=http://theprettyguineapig.com/topamax/ - topamax de 25 mg[/URL - [URL=http://frozenstar.net/item/veltride/ - veltride[/URL - [URL=http://herbalfront.com/pill/co-amoxiclav/ - walmart co amoxiclav price[/URL - [URL=http://herbalfront.com/pill/esidrix/ - esidrix price[/URL - [URL=http://kafelnikov.net/pill/zidovir/ - generic zidovir uk[/URL - [URL=http://shawntelwaajid.com/drugs/pregnyl/ - pregnyl[/URL - shining scans: stromectol cost of vrikshamla at canadian pharmacy dipyridamole lowest price buy celin w not prescription speman non generic flagyl er flagyl er for sale toradol toradol non generic blacksportsonline cialis rumalaya-gel apotek topamax website buy veltride online cheap buy co amoxiclav no prescription esidrix without prescription online zidovir no prescription walmart pregnyl price application, http://friendsofcalarchives.org/stromectol-for-sale-overnight/ purchase stromectol online http://friendsofcalarchives.org/vrikshamla/ order price vrikshamla http://umichicago.com/dipyridamole/ dipyridamole online http://christmastoysite.com/celin/ from generic india celin http://kafelnikov.net/item/speman/ speman http://damcf.org/flagyl-er/ online flagyl er http://globallifefoundation.org/item/toradol/ toradol http://foodfhonebook.com/coupons-for-cialis-viagra-levitra/ cialis cos http://shawntelwaajid.com/drugs/rumalaya-gel/ buy rumalaya-gel authentic best rumalaya-gel online http://theprettyguineapig.com/topamax/ topamax generic available http://frozenstar.net/item/veltride/ veltride http://herbalfront.com/pill/co-amoxiclav/ ordering co-amoxiclav online legal http://herbalfront.com/pill/esidrix/ esidrix commercial http://kafelnikov.net/pill/zidovir/ zidovir in farmacia http://shawntelwaajid.com/drugs/pregnyl/ pregnyl.com occurrences elastin node.

2022-05-16 11:27:29回复

1 ... 29411294122941329414294152941629417 ... 39047(有 195235 条评论)