国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP+javascript制作帶提示的驗證碼源碼分享

2024-05-04 23:23:56
字體:
供稿:網(wǎng)友

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 method="post" >
<table>
    <tr>
      <td ><div>驗證碼:</div></td>
      <td ><input type="text" size="8" onBlur="javascript:chkyzm(form)"/></td><td>
        <input type="hidden" value="" /></td>
      <td valign="middle"><script>yzm()</script></td>
      <td ><a href="javascript:code()">看不清</a></td>
      <td ><div><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);//隨機小數(shù)放大
 var num=num1.toString().substr(0,4);//取4位整數(shù)
 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);       //創(chuàng)建畫布
$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位隨機數(shù)
 $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)數(shù)字的模糊程度
}       //水平輸出字符串
for($i=0;$i<200;$i++){  //執(zhí)行for循環(huán),為驗證碼添加模糊背景
  $randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); //創(chuàng)建背景
  imagesetpixel($im,rand()%70,rand()%30,$randcolor);  //繪制單一元素
}
imagepng($im);    //生成png圖像
imagedestroy($im);   //銷毀圖像
?>

注意:PHP需要配置才能執(zhí)行相關(guān)方法。

運行效果:

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 凌云县| 屏边| 枝江市| 青铜峡市| 长春市| 双桥区| 平顶山市| 新民市| 公安县| 正宁县| 涿鹿县| 阿瓦提县| 信宜市| 安乡县| 五原县| 屏边| 桦南县| 图们市| 宣化县| 石首市| 黔东| 临邑县| 志丹县| 大同县| 工布江达县| 孝义市| 凤山市| 泰兴市| 柘荣县| 象山县| 灵台县| 洛南县| 巢湖市| 红桥区| 若尔盖县| 宜都市| 自治县| 竹北市| 文成县| 清流县| 沿河|