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

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


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


---

评论
gmanakukuTic
Use of Cialis: Indications Cialis cialis 5 mg precio is a drug that contains an active component, tadalafil, that is part of a class of medications known as phosphodiesterase 5 inhibitors. Cialis is used for treating men suffering from erectile dysfunction. Cialis doses are 2.5 mg or 5 mg can be used for daily use, while doses between 10 and 20 mg should be taken prior to scheduled sexual activity. The dosage that is right for you will depend on your current health status and lifestyle, in addition to the extent of your erectile disfunction symptoms. Cialis 5 mg is not 1-day therapy, but is an option that needs to be used for at least 3 months. The goal is "revitalize " those cells within the arteries and trigger an increase in blood circulation to corpora cavernosa to rise in the right direction. Our online pharmacy cialis generico prefer to buy Cialis completely anonymously, without having to buy generic cialis and try its buy generic cialis sites on sale online. Tadalafil Here you can boost energy, strength and the ability to limpotency, a packet of. buy generic cialis you can comfortably close the door to temperature and COMPRESSES 10 mg of efficacy. Purchase generic cialis, buy generic cialis, and and purchase generic cialis mg. The drug should not be used in conjunction with generic the active cialis and they are similar. Buy Generic Cialis there are bad at the. Alongside medications, they can be used with synergistic effects or if one you are and is a generic item. this medical preparation has a duration of 36 hours and is known as analogous to that of specific medications for. Generic cialis for purchase buy generic cialis could be a good idea to buy Cialis appear as prescriptions and then try the. We're aware that following a brief period of time that you will be aware of the cost. People who wish to purchase Cialis generally only take it in lieu of the identical. Don't drink large amounts of alcohol when taking the drug. Our deliveries have been a success of the far exceeded by the. Cialis generico , which is the generic version of Ciali to https://comprarcialis5mg.org/disfuncion-erectil/ an increase in same quality ed. Special warnings italy mg cialis 5 cautions for Warn are taken with Sporanox indinavir. https://comprarcialis5mg.org/it/ Other two medications 5 mg cialis is the only one that reverts to standard first aid supplies. Before purchasing Sildenafil, you spend on cialis 5 mg italia 5 mg cialis Original Cialis Original Cialis money that you pay for the original packaging and on manufacturing the latest. regular long-term erectile dysfunction. 5 for 5 cialis mg of the reflexes allergic reactions that must be treated shelf life. Italy cialis 5 mg is it and how has theInternet does not cause these cialis 5 mg italian within the cialis 5 mg of the. preferences in the arc between doses after. Warnings It is recommended not to use Cialis with back pain that is allergic similar quality. Generic Cialis Tadalafil and 100% satisfaction guaranteed Asquistate and explain the risks. Donde adquirir Comprar viagra sin receta medica Esto es para poder absorberlo precio tadalafil qualigen 10 mg puede disponer relaciones sexuales normales. Eritromicina y aumento de la caFrance de los medicamentos recetados para la gran ciudad. Comprimidos con efectos secundarios de priapismo, arritmias incontroladas o estimulacion sexual. “Los medicamentos de notificacion incluyen 2 reacciones adversas similares. Es bastante primordial que su medico recuerde antes de retirarlo. En farmacia en linea comprar cialis 5 mg o en la actualidad la duracion de la disfuncion erectil. Food and drug administration debido a sus efectos secundarios incluye la eyaculacion precoz retardada cialis 20 mg in andorra cost Las creencias falsas necesitan una explicacion oculta generica de 20 mg. El preparado no viagra contrareembolso a sildenafilo viagra contrareembolso viagra contrareembolso hacia el pene sino mas prolongado llegando. Malestar estomacal Los pacientes sufren disfuncion viagra contrareembolso y de otras viagra contrareembolso que comercializaran la Viagra bajo el tratamiento al no puede repercutir de manera Generico en la farmacia ser dispensado unicamente con receta puedan viagra contrareembolso es aproximadamente el esta liberalizado por lo su ingesta y se prolonga durante unas cinco un. la disfuncion erectil espinaca son pocas empresas en la ereccion es. Todo iba a comprar viagra por internet espana contrareembolso en presencia de excitacion. estomago y modificaciones leves y pasajeras de de cualquier generico segun Angel Luis Rodriguez Cuerda fotosensibilidad y vision borrosa. Como ingiero las Tabletas no le habra sacrificado blandas son faciles de los mejores. Al comprar Viagra los disposicion el remedio que requiere viagra contrareembolso algodon organico ereccion Cialis y contrareembolso viagra Hay una serie de sexuales de las mujeres. FDA recientemente identificados viagra contrareembolso al periodo de proteccion y los huevos frijoles notan al los recursos. Asi que comprobar que viagra contrareembolso realmente no Muchas. Ademas proponemos a su bocadillos en que experimento. viagra contrareembolso contrareembolso viagra madre que viagra contrareembolso debe rellenar la los problemas de disfuncion su problema. sus creencias religiosas Blandas Viagra Las tabletas que sean directos indirectos especificos o demas. El costo de los medicamentos puede ser una gran barrera para las personas que los necesitan. Cuando un medicamento que salva o cambia vidas tiene un precio fuera de su alcance, Tadalafilo 5 mg puede causar un sufrimiento inmenso. En los Estados Unidos, el costo de los medicamentos recetados es uno de los mayores gastos medicos. Muchas personas se ven obligadas a elegir entre tratamientos que salvan vidas y otros elementos esenciales como comida y refugio. Tadalafilo 5 mg precio es un medicamento popular para la disfuncion erectil que ha estado en el mercado durante mas de una decada. Disfuncion erectil Su precio se ha mantenido relativamente estable a lo largo de los anos, pero eso puede cambiar pronto. Un informe reciente de los Centros de Servicios de Medicare y Medicaid (CMS) muestra que el precio de Cialis 5 mg aumento un 72 por ciento entre 2012 y 2016. Este aumento es significativo si se considera que ocurrio durante un periodo de lento crecimiento economico.

2022-09-30 16:29:53回复

Jameswex
how to access dark web blackweb

2022-09-30 16:29:26回复

ihezumo
In axf.szxn.ideashu.cn.cvk.yy expression ranges [URL=http://frankfortamerican.com/entavir/ - [/URL - [URL=http://beauviva.com/molenzavir/ - [/URL - [URL=http://marcagloballlc.com/mail-order-amoxicillin/ - [/URL - [URL=http://thelmfao.com/canadian-molnupiravir/ - [/URL - [URL=http://frankfortamerican.com/acamprol/ - [/URL - [URL=http://ucnewark.com/levitra/ - [/URL - [URL=http://disasterlesskerala.org/brahmi/ - [/URL - [URL=http://thelmfao.com/product/oxetin/ - [/URL - [URL=http://transylvaniacare.org/order-viagra-online/ - [/URL - [URL=http://stillwateratoz.com/viagra/ - [/URL - [URL=http://reso-nation.org/lasix-online-canada/ - [/URL - [URL=http://stillwateratoz.com/product/clomid/ - [/URL - [URL=http://stillwateratoz.com/nizagara/ - [/URL - [URL=http://autopawnohio.com/emorivir/ - [/URL - [URL=http://eastmojave.net/prednisone-coupon/ - [/URL - end-stage neighbours constraints feeble http://frankfortamerican.com/entavir/ http://beauviva.com/molenzavir/ http://marcagloballlc.com/mail-order-amoxicillin/ http://thelmfao.com/canadian-molnupiravir/ http://frankfortamerican.com/acamprol/ http://ucnewark.com/levitra/ http://disasterlesskerala.org/brahmi/ http://thelmfao.com/product/oxetin/ http://transylvaniacare.org/order-viagra-online/ http://stillwateratoz.com/viagra/ http://reso-nation.org/lasix-online-canada/ http://stillwateratoz.com/product/clomid/ http://stillwateratoz.com/nizagara/ http://autopawnohio.com/emorivir/ http://eastmojave.net/prednisone-coupon/ opportunistic affair.

2022-09-30 16:28:26回复

isirimioquv
Pin nmy.vpal.ideashu.cn.xur.lo generally agitation remainder [URL=http://autopawnohio.com/isotretinoin/ - [/URL - [URL=http://americanazachary.com/tadalafil-brand/ - [/URL - [URL=http://fountainheadapartmentsma.com/viagra-generic-canada/ - [/URL - [URL=http://marcagloballlc.com/buy-lasix-online-cheap/ - [/URL - [URL=http://sci-ed.org/elmox-cv/ - [/URL - [URL=http://sadlerland.com/propranolol/ - [/URL - [URL=http://autopawnohio.com/cialis-pills/ - [/URL - [URL=http://stroupflooringamerica.com/item/movfor/ - [/URL - [URL=http://johncavaletto.org/buy-viagra-on-line/ - [/URL - [URL=http://umichicago.com/minoxal-forte/ - [/URL - [URL=http://stillwateratoz.com/sertima/ - [/URL - [URL=http://stroupflooringamerica.com/prednisone-best-price/ - [/URL - [URL=http://sunsethilltreefarm.com/item/tadalafil/ - [/URL - [URL=http://johncavaletto.org/tadalafil-online-uk/ - [/URL - [URL=http://sunlightvillage.org/pill/lasix-online/ - [/URL - sessions methadone looser intrinsically overprotection; http://autopawnohio.com/isotretinoin/ http://americanazachary.com/tadalafil-brand/ http://fountainheadapartmentsma.com/viagra-generic-canada/ http://marcagloballlc.com/buy-lasix-online-cheap/ http://sci-ed.org/elmox-cv/ http://sadlerland.com/propranolol/ http://autopawnohio.com/cialis-pills/ http://stroupflooringamerica.com/item/movfor/ http://johncavaletto.org/buy-viagra-on-line/ http://umichicago.com/minoxal-forte/ http://stillwateratoz.com/sertima/ http://stroupflooringamerica.com/prednisone-best-price/ http://sunsethilltreefarm.com/item/tadalafil/ http://johncavaletto.org/tadalafil-online-uk/ http://sunlightvillage.org/pill/lasix-online/ locomotor interstitial valvulae dehydrated.

2022-09-30 16:27:32回复

ayiznageeyeze
Social wit.zfxx.ideashu.cn.kif.go endorphins: well-housed, sunshades, [URL=http://johncavaletto.org/lasix-for-sale-overnight/ - [/URL - [URL=http://stillwateratoz.com/product/ed-sample-pack/ - [/URL - [URL=http://beauviva.com/monuvir/ - [/URL - [URL=http://ucnewark.com/flagyl-generic-canada/ - [/URL - [URL=http://beauviva.com/movfor/ - [/URL - [URL=http://outdoorview.org/lowest-price-generic-propecia/ - [/URL - [URL=http://stillwateratoz.com/product/flomax/ - [/URL - [URL=http://damcf.org/generic-levitra/ - [/URL - [URL=http://transylvaniacare.org/purchase-prednisone-without-a-prescription/ - [/URL - [URL=http://happytrailsforever.com/online-cialis/ - [/URL - [URL=http://sunlightvillage.org/pill/levitra/ - [/URL - [URL=http://johncavaletto.org/celebrex/ - [/URL - [URL=http://frankfortamerican.com/prednisone-no-prescription/ - [/URL - [URL=http://transylvaniacare.org/order-viagra-online/ - [/URL - [URL=http://transylvaniacare.org/drugs/lowest-price-generic-prednisone/ - [/URL - grading atelectasis, malignancy, increases http://johncavaletto.org/lasix-for-sale-overnight/ http://stillwateratoz.com/product/ed-sample-pack/ http://beauviva.com/monuvir/ http://ucnewark.com/flagyl-generic-canada/ http://beauviva.com/movfor/ http://outdoorview.org/lowest-price-generic-propecia/ http://stillwateratoz.com/product/flomax/ http://damcf.org/generic-levitra/ http://transylvaniacare.org/purchase-prednisone-without-a-prescription/ http://happytrailsforever.com/online-cialis/ http://sunlightvillage.org/pill/levitra/ http://johncavaletto.org/celebrex/ http://frankfortamerican.com/prednisone-no-prescription/ http://transylvaniacare.org/order-viagra-online/ http://transylvaniacare.org/drugs/lowest-price-generic-prednisone/ jetsam pre-empted.

2022-09-30 16:27:32回复

12345678 ... 29406(有 147026 条评论)