驗(yàn)證碼:<\/div><\/td>\r\n
<\/td> | \r\n <\/td>\r\n |
Home
Backend Development
PHP Tutorial
PHP+javascript creates verification code source code with prompts for sharing
PHP+javascript creates verification code source code with prompts for sharing
Jan 13, 2017 pm 02:44 PM
html code: <!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>簡(jiǎn)單驗(yàn)證碼</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">驗(yàn)證碼:</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">請(qǐng)輸入驗(yàn)證碼</font></div></td>
</tr>
</table>
</form>
</body>
</html> JS code: function chkyzm(form){ //對(duì)驗(yàn)證碼進(jìn)行驗(yàn)證
if(form.yzm.value==""){
yzm1.innerHTML="<font color=#FF0000>×驗(yàn)證碼不能為空</font>";
}else if(form.yzm.value!=form.yzm2.value){
yzm1.innerHTML="<font color=#FF0000>×驗(yàn)證碼輸入錯(cuò)誤</font>";
}else{
yzm1.innerHTML="<font color=green>√驗(yàn)證碼輸入正確</font>";
}
}
function yzm(){ //生成驗(yàn)證碼
var num1=Math.round(Math.random()*1000000);//隨機(jī)小數(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(){ //重置驗(yàn)證碼
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 code: <?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位隨機(jī)數(shù)
$str=mt_rand(1,5); //定義隨機(jī)字符所在位置的的Y坐標(biāo)
$size=mt_rand(6,9); //定義隨機(jī)字符的字體
$authnum=substr($_GET[num],$i,1); //獲取超級(jí)鏈接中傳遞的驗(yàn)證碼
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),為驗(yà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); //銷毀圖像
?> Note: PHP needs to be configured to execute related methods.
For more PHP+javascript production and prompt verification code source code sharing related articles, please pay attention to the PHP Chinese website!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do I implement authentication and authorization in PHP?
Jun 20, 2025 am 01:03 AM
TosecurelyhandleauthenticationandauthorizationinPHP,followthesesteps:1.Alwayshashpasswordswithpassword_hash()andverifyusingpassword_verify(),usepreparedstatementstopreventSQLinjection,andstoreuserdatain$_SESSIONafterlogin.2.Implementrole-basedaccessc
How can you handle file uploads securely in PHP?
Jun 19, 2025 am 01:05 AM
To safely handle file uploads in PHP, the core is to verify file types, rename files, and restrict permissions. 1. Use finfo_file() to check the real MIME type, and only specific types such as image/jpeg are allowed; 2. Use uniqid() to generate random file names and store them in non-Web root directory; 3. Limit file size through php.ini and HTML forms, and set directory permissions to 0755; 4. Use ClamAV to scan malware to enhance security. These steps effectively prevent security vulnerabilities and ensure that the file upload process is safe and reliable.
What are the differences between == (loose comparison) and === (strict comparison) in PHP?
Jun 19, 2025 am 01:07 AM
In PHP, the main difference between == and == is the strictness of type checking. ==Type conversion will be performed before comparison, for example, 5=="5" returns true, and ===Request that the value and type are the same before true will be returned, for example, 5==="5" returns false. In usage scenarios, === is more secure and should be used first, and == is only used when type conversion is required.
How do I perform arithmetic operations in PHP ( , -, *, /, %)?
Jun 19, 2025 pm 05:13 PM
The methods of using basic mathematical operations in PHP are as follows: 1. Addition signs support integers and floating-point numbers, and can also be used for variables. String numbers will be automatically converted but not recommended to dependencies; 2. Subtraction signs use - signs, variables are the same, and type conversion is also applicable; 3. Multiplication signs use * signs, which are suitable for numbers and similar strings; 4. Division uses / signs, which need to avoid dividing by zero, and note that the result may be floating-point numbers; 5. Taking the modulus signs can be used to judge odd and even numbers, and when processing negative numbers, the remainder signs are consistent with the dividend. The key to using these operators correctly is to ensure that the data types are clear and the boundary situation is handled well.
How can you interact with NoSQL databases (e.g., MongoDB, Redis) from PHP?
Jun 19, 2025 am 01:07 AM
Yes, PHP can interact with NoSQL databases like MongoDB and Redis through specific extensions or libraries. First, use the MongoDBPHP driver (installed through PECL or Composer) to create client instances and operate databases and collections, supporting insertion, query, aggregation and other operations; second, use the Predis library or phpredis extension to connect to Redis, perform key-value settings and acquisitions, and recommend phpredis for high-performance scenarios, while Predis is convenient for rapid deployment; both are suitable for production environments and are well-documented.
What is PHP, and why is it used for web development?
Jun 23, 2025 am 12:55 AM
PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti
How to set PHP time zone?
Jun 25, 2025 am 01:00 AM
TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez
See all articles
|