本文实例为大家分享了php封装的一个生成图像验证码,供大家参考,具体内容如下

一、代码

index..php

<!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=utf-8" /> 
<title>js+GD2函数制作无刷新验证码</title> 
<link rel="stylesheet" type="text/css" href="css/style.css" rel="external nofollow" > 
</head> 
<body> 
<div style="width: 750px; border: 1px solid #0D6C8C; text-align: left"> 
 <div style="width:100%; height:25px; border:1px #FFFFFF solid; background:url(img/t-background.gif); color:#FFFFFF; padding-top:5px; padding-left:20px; text-align:left">填写用户注册信息</div> 
 <div style="width:400px; text-align:left; padding-left:50px; padding-top:15px; float:left"> 
<script language="javascript"> 
  function chkinput(form) 
  { 
    if (form.username.value==''){ 
      alert('请输入用户名!'); 
      form.username.focus(); 
      return false; 
    } 
     
    if (form.password.value==''){ 
      alert('请输入注册密码!'); 
      form.password.focus(); 
      return false; 
    }   
     
    if (form.defPassword.value==''){ 
      alert('请输入确认密码!'); 
      form.defPassword.focus(); 
      return false; 
    } 
     
    if (form.password.value.length<6){ 
      alert('密码长度应大于6位!'); 
      form.password.focus(); 
      return false; 
    } 
     
    if (form.password.value!=form.defPassword.value){ 
      alert('密码与确认密码不同!'); 
      form.password.focus(); 
      return false; 
    } 
     
    if (form . email . value == "") { 
      alert("请输入E-mail地址!"); 
      form . email . select(); 
      return (false); 
    } 
    var i= form . email . value . indexOf("@"); 
    if (i < 0) { 
      alert("请输入正确的E-mail地址!"); 
      form . email . select(); 
      return (false); 
    } 
    if (form . tel . value == "") { 
      alert('请输入电话号码!'); 
      form . tel . focus(); 
      return (false); 
    } 
    var t=/^([0-9]|[\-])+$/g; 
    if (! t . test(form . tel . value) || form . tel . value . length > 18 || form . tel . value . length < 7) { 
      alert('电话格式输入有误!'); 
      form . tel . focus(); 
      return (false); 
    } 
                   
    if (form.address.value==''){ 
      alert('请输入联系地址!'); 
      form.address.focus(); 
      return false; 
    } 
     
    if (form.validatorCode.value==''){ 
      alert('请输入验证码!'); 
      form.validatorCode.focus(); 
      return false; 
    } 
     
    if (form.validatorCode.value!=form.defValidatorCode.value) { 
      alert('验证码输入有误!'); 
      form.validatorCode.focus(); 
      return false; 
    } 
     
    return true; 
   
  } 
</script> 
   
<form name="form1" method="post" action="success.php" onSubmit="return chkinput(this)"> 
用户名:&nbsp;&nbsp;<input type="text" name="username" size="30" class="input" /><br><br> 
密&nbsp;&nbsp;码:&nbsp;&nbsp;<input type="password" name="password" size="30" class="input" /><br><br> 
确认密码:<input type="password" name="defPassword" size="30" class="input"><br><br> 
E-mail:&nbsp;&nbsp;<input type="text" name="email" size="30" class="input" /><br><br> 
电话:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="tel" size="30" class="input" /><br><br> 
联系地址:<input type="text" name="address" size="30" class="input" /><br><br> 
验证码:&nbsp;&nbsp;<input type="text" name="validatorCode" size="10" class="input" /> 
<input type="hidden" name="defValidatorCode" value="" /> 
   
  <script language="javascript"> 
   var num1=Math.round(Math.random()*10000000); 
   var num=num1.toString().substr(0,4); 
   document.write("<img name=codeimg src='TestCode.php"+num+"'>"); 
   form1.defValidatorCode.value=num; 
   function reCode(){ 
      var num1=Math.round(Math.random()*10000000); 
      var num=num1.toString().substr(0,4); 
      document.codeimg.src="/UploadFiles/2021-04-02/TestCode.php">
<"text-align: center">php图像验证码生成代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
php图像验证码生成,php图像验证码,php验证码生成

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“php图像验证码生成代码”

暂无“php图像验证码生成代码”评论...