html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>简单验证码</title> </head> <script language="javascript" src="js/checked.js"></script> <body> <form id="register" name="register" method="post" > <table align="center"> <tr> <td ><div align="right">验证码:</div></td> <td ><input id="yzm" type="text" name="yzm" size="8" onBlur="javascript:chkyzm(form)" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"/></td><td> <input id="yzm2" type="hidden" value="" /></td> <td align="center" valign="middle"><script>yzm()</script></td> <td ><a href="javascript:code()" style="text-decoration:none">看不清</a></td> <td width="150" align="center"><div id="yzm1"><font color="#999999">请输入验证码</font></div></td> </tr> </table> </form> </body> </html>
JS代码:
function chkyzm(form){ //对验证码进行验证 if(form.yzm.value==""){ yzm1.innerHTML="<font color=#FF0000>×验证码不能为空</font>"; }else if(form.yzm.value!=form.yzm2.value){ yzm1.innerHTML="<font color=#FF0000>×验证码输入错误</font>"; }else{ yzm1.innerHTML="<font color=green>√验证码输入正确</font>"; } } function yzm(){ //生成验证码 var num1=Math.round(Math.random()*1000000);//随机小数放大 var num=num1.toString().substr(0,4);//取4位整数 var yzm2=document.getElementById("yzm2"); document.write("<img name=codeimg src=yzm.php?num="+num+"'>"); yzm2.value=num; } function code(){ //重置验证码 var num1=Math.round(Math.random()*1000000); var num=num1.toString().substr(0,4); var yzm2=document.getElementById("yzm2"); document.codeimg.src="yzm.php?num="+num; yzm2.value=num; }
yzm.php代码:
<?php header("Content-type: image/png"); $im=imagecreate(66,22); //创建画布 $black=imagecolorallocate($im,0,0,0); //定义背景 $white=imagecolorallocate($im,255,255,255); //定义背景 $gray=imagecolorallocate($im,200,200,200); //定义背景 imagefill($im,0,0,$gray); //填充颜色 for($i=0;$i<4;$i++){ //定义4位随机数 $str=mt_rand(1,5); //定义随机字符所在位置的的Y坐标 $size=mt_rand(6,9); //定义随机字符的字体 $authnum=substr($_GET[num],$i,1); //获取超级链接中传递的验证码 imagestring($im,$size,(3+$i*15),$str,$authnum,imagecolorallocate($im,rand(0,250),rand(0,250),rand(0,250)));//rand(0,500)数字的模糊程度 } //水平输出字符串 for($i=0;$i<200;$i++){ //执行for循环,为验证码添加模糊背景 $randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); //创建背景 imagesetpixel($im,rand()%70,rand()%30,$randcolor); //绘制单一元素 } imagepng($im); //生成png图像 imagedestroy($im); //销毁图像 ?>
注意:PHP需要配置才能执行相关方法。
更多PHP+javascript制作带提示的验证码源码分享相关文章请关注PHP中文网!

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

使用依赖注入(DI)的原因是它促进了代码的松耦合、可测试性和可维护性。1)使用构造函数注入依赖,2)避免使用服务定位器,3)利用依赖注入容器管理依赖,4)通过注入依赖提高测试性,5)避免过度注入依赖,6)考虑DI对性能的影响。

phperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovesponsemetimes.2)优化

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

TOOPTIMIZEPHPAPPLICITIONSFORPERSTORANCE,USECACHING,数据库imization,opcodecaching和SererverConfiguration.1)InlumentCachingWithApcutCutoredSatfetchTimes.2)优化的atabasesbasesebasesebasesbasesbasesbaysbysbyIndexing,BeallancingAndWriteExing

依赖性注射inphpisadesignpatternthatenhancesFlexibility,可检验性和ManiaginabilybyByByByByByExternalDependencEctenceScoupling.itallowsforloosecoupling,EasiererTestingThroughMocking,andModularDesign,andModularDesign,butquirscarecarefulscarefullsstructoringDovairing voavoidOverOver-Inje

PHP性能优化可以通过以下步骤实现:1)在脚本顶部使用require_once或include_once减少文件加载次数;2)使用预处理语句和批处理减少数据库查询次数;3)配置OPcache进行opcode缓存;4)启用并配置PHP-FPM优化进程管理;5)使用CDN分发静态资源;6)使用Xdebug或Blackfire进行代码性能分析;7)选择高效的数据结构如数组;8)编写模块化代码以优化执行。

opcodecachingsimplovesphperforvesphpermance bycachingCompiledCode,reducingServerLoadAndResponSetimes.1)itstorescompiledphpcodeinmemory,bypassingparsingparsingparsingandcompiling.2)useopcachebachebachebachebachebachebachebysettingparametersinphametersinphp.ini,likeememeryconmorysmorysmeryplement.33)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具