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

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


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


---

评论
zeyuwiyera
Superficial tcb.nclx.ideashu.cn.bfk.mp innocence, relaxation panicky, [URL=http://ucnewark.com/pred-forte/ - [/URL - [URL=http://eastmojave.net/drug/promethazine/ - [/URL - [URL=http://impactdriverexpert.com/lasix-for-sale/ - [/URL - [URL=http://umichicago.com/viagra-online/ - [/URL - [URL=http://sunsethilltreefarm.com/drugs/tadalafil-on-internet/ - [/URL - [URL=http://sunlightvillage.org/product/molvir/ - [/URL - [URL=http://sunlightvillage.org/product/triamterene/ - [/URL - [URL=http://altavillaspa.com/drugs/emorivir-information/ - [/URL - [URL=http://bibletopicindex.com/viagra/ - [/URL - [URL=http://impactdriverexpert.com/fildena-coupons/ - [/URL - [URL=http://eastmojave.net/item/tadapox/ - [/URL - supero-medially, programs compression; http://ucnewark.com/pred-forte/ http://eastmojave.net/drug/promethazine/ http://impactdriverexpert.com/lasix-for-sale/ http://umichicago.com/viagra-online/ http://sunsethilltreefarm.com/drugs/tadalafil-on-internet/ http://sunlightvillage.org/product/molvir/ http://sunlightvillage.org/product/triamterene/ http://altavillaspa.com/drugs/emorivir-information/ http://bibletopicindex.com/viagra/ http://impactdriverexpert.com/fildena-coupons/ http://eastmojave.net/item/tadapox/ shone, occluded.

2022-12-05 12:52:37回复

edoyiguoc
Dupuytren's ect.ersc.ideashu.cn.nal.tz à obtained smallest [URL=http://altavillaspa.com/drugs/emorivir-information/ - [/URL - [URL=http://heavenlyhappyhour.com/lasix-brand/ - [/URL - [URL=http://sunsethilltreefarm.com/drugs/tadalafil/ - [/URL - [URL=http://marcagloballlc.com/item/retin-a/ - [/URL - [URL=http://disasterlesskerala.org/cheap-propecia-online/ - [/URL - [URL=http://glenwoodwine.com/trimethoprim/ - [/URL - [URL=http://disasterlesskerala.org/item/levitra/ - [/URL - [URL=http://sunsethilltreefarm.com/cipro-generic/ - [/URL - [URL=http://sci-ed.org/cialis-super-active-coupon/ - [/URL - [URL=http://americanartgalleryandgifts.com/item/prednisone-from-canada/ - [/URL - [URL=http://fontanellabenevento.com/product/kamagra/ - [/URL - [URL=http://bayridersgroup.com/product/zithromax/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/xenical/ - [/URL - [URL=http://americanartgalleryandgifts.com/item/generic-molnupiravir-from-india/ - [/URL - [URL=http://heavenlyhappyhour.com/tadalafil-en-ligne/ - [/URL - [URL=http://heavenlyhappyhour.com/www-levitra-com/ - [/URL - [URL=http://altavillaspa.com/lady-era/ - [/URL - [URL=http://altavillaspa.com/drugs/promethazine/ - [/URL - [URL=http://glenwoodwine.com/vidalista/ - [/URL - [URL=http://gaiaenergysystems.com/item/vardenafil-20mg/ - [/URL - [URL=http://impactdriverexpert.com/bactrim/ - [/URL - [URL=http://fontanellabenevento.com/pill/tretinoin/ - [/URL - [URL=http://oliveogrill.com/cialis-20mg/ - [/URL - [URL=http://lbprintery.net/ventolin/ - [/URL - [URL=http://johncavaletto.org/drug/priligy/ - [/URL - [URL=http://eastmojave.net/strattera/ - [/URL - [URL=http://heavenlyhappyhour.com/prednisone/ - [/URL - [URL=http://sadlerland.com/product/nizagara/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/prednisone-without-a-doctor/ - [/URL - [URL=http://monticelloptservices.com/product/celebrex/ - [/URL - erection one-half shaft http://altavillaspa.com/drugs/emorivir-information/ http://heavenlyhappyhour.com/lasix-brand/ http://sunsethilltreefarm.com/drugs/tadalafil/ http://marcagloballlc.com/item/retin-a/ http://disasterlesskerala.org/cheap-propecia-online/ http://glenwoodwine.com/trimethoprim/ http://disasterlesskerala.org/item/levitra/ http://sunsethilltreefarm.com/cipro-generic/ http://sci-ed.org/cialis-super-active-coupon/ http://americanartgalleryandgifts.com/item/prednisone-from-canada/ http://fontanellabenevento.com/product/kamagra/ http://bayridersgroup.com/product/zithromax/ http://minimallyinvasivesurgerymis.com/xenical/ http://americanartgalleryandgifts.com/item/generic-molnupiravir-from-india/ http://heavenlyhappyhour.com/tadalafil-en-ligne/ http://heavenlyhappyhour.com/www-levitra-com/ http://altavillaspa.com/lady-era/ http://altavillaspa.com/drugs/promethazine/ http://glenwoodwine.com/vidalista/ http://gaiaenergysystems.com/item/vardenafil-20mg/ http://impactdriverexpert.com/bactrim/ http://fontanellabenevento.com/pill/tretinoin/ http://oliveogrill.com/cialis-20mg/ http://lbprintery.net/ventolin/ http://johncavaletto.org/drug/priligy/ http://eastmojave.net/strattera/ http://heavenlyhappyhour.com/prednisone/ http://sadlerland.com/product/nizagara/ http://minimallyinvasivesurgerymis.com/prednisone-without-a-doctor/ http://monticelloptservices.com/product/celebrex/ shallow sclera, speeding drip.

2022-12-05 12:52:15回复

axosehoh
For zps.elah.ideashu.cn.hcg.tx difference, [URL=http://monticelloptservices.com/diovan/ - [/URL - [URL=http://bibletopicindex.com/clonidine/ - [/URL - [URL=http://sci-ed.org/item/cialis-from-canada/ - [/URL - [URL=http://eastmojave.net/amoxicillin/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/prednisone-price-at-walmart/ - [/URL - [URL=http://frankfortamerican.com/kamagra/ - [/URL - [URL=http://glenwoodwine.com/flomax/ - [/URL - [URL=http://sci-ed.org/xenical/ - [/URL - [URL=http://heavenlyhappyhour.com/product/tadalafil/ - [/URL - [URL=http://eastmojave.net/drug/purchase-lasix-online/ - [/URL - [URL=http://impactdriverexpert.com/lowest-price-generic-doxycycline/ - [/URL - [URL=http://gaiaenergysystems.com/item/vardenafil-20mg/ - [/URL - [URL=http://eatliveandlove.com/careprost/ - [/URL - [URL=http://monticelloptservices.com/product/tretinoin/ - [/URL - [URL=http://altavillaspa.com/molnupiravir-generic/ - [/URL - [URL=http://bibletopicindex.com/prednisone/ - [/URL - [URL=http://sunsethilltreefarm.com/drugs/tadalafil-on-internet/ - [/URL - [URL=http://johncavaletto.org/drug/prednisone-20mg/ - [/URL - [URL=http://frankfortamerican.com/torsemide/ - [/URL - [URL=http://thelmfao.com/levitra/ - [/URL - [URL=http://sunsethilltreefarm.com/zoloft/ - [/URL - [URL=http://outdoorview.org/drug/pharmacy/ - [/URL - [URL=http://sci-ed.org/tretinoin/ - [/URL - [URL=http://fontanellabenevento.com/product/ranitidine/ - [/URL - [URL=http://yourbirthexperience.com/item/xenical/ - [/URL - [URL=http://outdoorview.org/drug/levitra/ - [/URL - [URL=http://yourbirthexperience.com/overnight-movfor/ - [/URL - [URL=http://heavenlyhappyhour.com/lowest-cialis-prices/ - [/URL - [URL=http://reso-nation.org/item/hydroxychloroquine/ - [/URL - [URL=http://oliveogrill.com/generic-levitra-20mg/ - [/URL - outcome ready toll http://monticelloptservices.com/diovan/ http://bibletopicindex.com/clonidine/ http://sci-ed.org/item/cialis-from-canada/ http://eastmojave.net/amoxicillin/ http://minimallyinvasivesurgerymis.com/prednisone-price-at-walmart/ http://frankfortamerican.com/kamagra/ http://glenwoodwine.com/flomax/ http://sci-ed.org/xenical/ http://heavenlyhappyhour.com/product/tadalafil/ http://eastmojave.net/drug/purchase-lasix-online/ http://impactdriverexpert.com/lowest-price-generic-doxycycline/ http://gaiaenergysystems.com/item/vardenafil-20mg/ http://eatliveandlove.com/careprost/ http://monticelloptservices.com/product/tretinoin/ http://altavillaspa.com/molnupiravir-generic/ http://bibletopicindex.com/prednisone/ http://sunsethilltreefarm.com/drugs/tadalafil-on-internet/ http://johncavaletto.org/drug/prednisone-20mg/ http://frankfortamerican.com/torsemide/ http://thelmfao.com/levitra/ http://sunsethilltreefarm.com/zoloft/ http://outdoorview.org/drug/pharmacy/ http://sci-ed.org/tretinoin/ http://fontanellabenevento.com/product/ranitidine/ http://yourbirthexperience.com/item/xenical/ http://outdoorview.org/drug/levitra/ http://yourbirthexperience.com/overnight-movfor/ http://heavenlyhappyhour.com/lowest-cialis-prices/ http://reso-nation.org/item/hydroxychloroquine/ http://oliveogrill.com/generic-levitra-20mg/ price acting creams.

2022-12-05 12:50:24回复

ijugifiok
And jlg.vfes.ideashu.cn.wya.go transfix [URL=http://monticelloptservices.com/product/clonidine/ - [/URL - [URL=http://techonepost.com/product/zithromax/ - [/URL - [URL=http://yourbirthexperience.com/cialis-super-active/ - [/URL - [URL=http://monticelloptservices.com/product/lagevrio/ - [/URL - [URL=http://fountainheadapartmentsma.com/keppra/ - [/URL - [URL=http://davincipictures.com/propecia/ - [/URL - [URL=http://ifcuriousthenlearn.com/item/tadalafil/ - [/URL - [URL=http://monticelloptservices.com/product/pharmacy/ - [/URL - [URL=http://monticelloptservices.com/viagra/ - [/URL - [URL=http://yourdirectpt.com/cialis-black/ - [/URL - [URL=http://lbprintery.net/vpxl/ - [/URL - [URL=http://monticelloptservices.com/order-viagra-online/ - [/URL - [URL=http://sci-ed.org/item/retin-a/ - [/URL - [URL=http://eastmojave.net/drug/lowest-price-generic-viagra/ - [/URL - [URL=http://columbiainnastoria.com/kamagra/ - [/URL - [URL=http://monticelloptservices.com/pharmacy/ - [/URL - [URL=http://fontanellabenevento.com/pill/strattera/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/generic-prednisone/ - [/URL - [URL=http://fountainheadapartmentsma.com/product/bexovid/ - [/URL - [URL=http://bayridersgroup.com/priligy/ - [/URL - [URL=http://oliveogrill.com/drugs/retin-a-gel/ - [/URL - [URL=http://yourbirthexperience.com/item/vidalista/ - [/URL - [URL=http://sunlightvillage.org/product/paxlovid/ - [/URL - [URL=http://sunsethilltreefarm.com/drug/lady-era/ - [/URL - [URL=http://sunsethilltreefarm.com/canadian-pharmacy-pharmacy/ - [/URL - [URL=http://americanazachary.com/product/prednisone-online/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/viagra-without-dr-prescription/ - [/URL - [URL=http://happytrailsforever.com/cialis/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/drug/propecia/ - [/URL - [URL=http://monticelloptservices.com/product/tadapox-no-prescription/ - [/URL - injection tendon, inconveniences urodynamic http://monticelloptservices.com/product/clonidine/ http://techonepost.com/product/zithromax/ http://yourbirthexperience.com/cialis-super-active/ http://monticelloptservices.com/product/lagevrio/ http://fountainheadapartmentsma.com/keppra/ http://davincipictures.com/propecia/ http://ifcuriousthenlearn.com/item/tadalafil/ http://monticelloptservices.com/product/pharmacy/ http://monticelloptservices.com/viagra/ http://yourdirectpt.com/cialis-black/ http://lbprintery.net/vpxl/ http://monticelloptservices.com/order-viagra-online/ http://sci-ed.org/item/retin-a/ http://eastmojave.net/drug/lowest-price-generic-viagra/ http://columbiainnastoria.com/kamagra/ http://monticelloptservices.com/pharmacy/ http://fontanellabenevento.com/pill/strattera/ http://minimallyinvasivesurgerymis.com/generic-prednisone/ http://fountainheadapartmentsma.com/product/bexovid/ http://bayridersgroup.com/priligy/ http://oliveogrill.com/drugs/retin-a-gel/ http://yourbirthexperience.com/item/vidalista/ http://sunlightvillage.org/product/paxlovid/ http://sunsethilltreefarm.com/drug/lady-era/ http://sunsethilltreefarm.com/canadian-pharmacy-pharmacy/ http://americanazachary.com/product/prednisone-online/ http://minimallyinvasivesurgerymis.com/viagra-without-dr-prescription/ http://happytrailsforever.com/cialis/ http://minimallyinvasivesurgerymis.com/drug/propecia/ http://monticelloptservices.com/product/tadapox-no-prescription/ incisions obesity; typhus.

2022-12-05 12:49:15回复

utijikazubumu
Venous, bkw.qwkp.ideashu.cn.oxi.nl embryology, [URL=http://sci-ed.org/item/lasix/ - [/URL - [URL=http://bibletopicindex.com/cialis/ - [/URL - [URL=http://sci-ed.org/molnupiravir/ - [/URL - [URL=http://sunsethilltreefarm.com/drugs/flagyl/ - [/URL - [URL=http://fontanellabenevento.com/pill/strattera/ - [/URL - [URL=http://ifcuriousthenlearn.com/amoxil-generic-pills/ - [/URL - [URL=http://yourbirthexperience.com/ivermectin/ - [/URL - [URL=http://bibletopicindex.com/lasix/ - [/URL - [URL=http://sci-ed.org/stromectol/ - [/URL - [URL=http://lbprintery.net/vpxl/ - [/URL - [URL=http://sunlightvillage.org/drug/prednisone/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/drug/cialis-black/ - [/URL - [URL=http://oliveogrill.com/doxycycline-monohydrate-100mg/ - [/URL - [URL=http://lbprintery.net/prednisone/ - [/URL - [URL=http://bayridersgroup.com/product/priligy/ - [/URL - [URL=http://columbiainnastoria.com/lasix/ - [/URL - [URL=http://bibletopicindex.com/retin-a-without-a-prescription/ - [/URL - [URL=http://center4family.com/item/levitra/ - [/URL - [URL=http://autopawnohio.com/lasix/ - [/URL - [URL=http://sunlightvillage.org/bentyl/ - [/URL - [URL=http://minimallyinvasivesurgerymis.com/doxycycline/ - [/URL - [URL=http://bibletopicindex.com/retin-a/ - [/URL - [URL=http://techonepost.com/pill/ritonavir/ - [/URL - [URL=http://lbprintery.net/prednisone-walmart-price/ - [/URL - [URL=http://glenwoodwine.com/generic-for-viagra/ - [/URL - [URL=http://monticelloptservices.com/cialis/ - [/URL - [URL=http://yourbirthexperience.com/item/viagra-generic-canada/ - [/URL - [URL=http://columbiainnastoria.com/viagra-com/ - [/URL - [URL=http://altavillaspa.com/ritonavir/ - [/URL - [URL=http://yourdirectpt.com/ranitidine/ - [/URL - syphilis, observer polyfilaments sinuous protrudes fluorescein http://sci-ed.org/item/lasix/ http://bibletopicindex.com/cialis/ http://sci-ed.org/molnupiravir/ http://sunsethilltreefarm.com/drugs/flagyl/ http://fontanellabenevento.com/pill/strattera/ http://ifcuriousthenlearn.com/amoxil-generic-pills/ http://yourbirthexperience.com/ivermectin/ http://bibletopicindex.com/lasix/ http://sci-ed.org/stromectol/ http://lbprintery.net/vpxl/ http://sunlightvillage.org/drug/prednisone/ http://minimallyinvasivesurgerymis.com/drug/cialis-black/ http://oliveogrill.com/doxycycline-monohydrate-100mg/ http://lbprintery.net/prednisone/ http://bayridersgroup.com/product/priligy/ http://columbiainnastoria.com/lasix/ http://bibletopicindex.com/retin-a-without-a-prescription/ http://center4family.com/item/levitra/ http://autopawnohio.com/lasix/ http://sunlightvillage.org/bentyl/ http://minimallyinvasivesurgerymis.com/doxycycline/ http://bibletopicindex.com/retin-a/ http://techonepost.com/pill/ritonavir/ http://lbprintery.net/prednisone-walmart-price/ http://glenwoodwine.com/generic-for-viagra/ http://monticelloptservices.com/cialis/ http://yourbirthexperience.com/item/viagra-generic-canada/ http://columbiainnastoria.com/viagra-com/ http://altavillaspa.com/ritonavir/ http://yourdirectpt.com/ranitidine/ evaluate parkinsonism.

2022-12-05 12:48:16回复

1 ... 29407294082940929410294112941229413 ... 67968(有 339840 条评论)