Php+javascript to make the code with the hint code sharing _php instance

Source: Internet
Author: User
HTML code:

Copy the Code code as follows:




Simple Verification Code






JS Code:

Copy the Code code as follows:
function Chkyzm (form) {//Verify the verification code
if (form.yzm.value== "") {
Yzm1.innerhtml= "x verification code cannot be empty";
}else if (form.yzm.value!=form.yzm2.value) {
Yzm1.innerhtml= "x Verification code input error";
}else{
Yzm1.innerhtml= "√ Verify code input is correct";
}
}
function Yzm () {//Generate verification code
var num1=math.round (Math.random () *1000000);//Random decimal amplification
var num=num1.tostring (). substr (0,4);//take 4-bit integers
var Yzm2=document.getelementbyid ("yzm2");
document.write ("");
Yzm2.value=num;
}
function code () {//Reset verification 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 Code:

Copy the Code code as follows:
Header ("Content-type:image/png");
$im =imagecreate (66,22); Create a canvas
$black =imagecolorallocate ($im, 0,0,0); Define Background
$white =imagecolorallocate ($im, 255,255,255); Define Background
$gray =imagecolorallocate ($im, 200,200,200); Define Background
Imagefill ($im, 0,0, $gray); Fill Color
for ($i =0; $i <4; $i + +) {//define 4-bit random number
$str =mt_rand (1,5); Defines the y-coordinate of where random characters are located
$size =mt_rand (6,9); Define a font for random characters
$authnum =substr ($_get[num], $i, 1); Get the verification code passed in the hyperlink
Imagestring ($im, $size, ($i *15), $str, $authnum, Imagecolorallocate ($im, Rand (0,250), Rand (0,250), Rand (0,250)));// Rand (0,500) the degree of ambiguity in numbers
}//Horizontal output string
for ($i =0; $i <200; $i + +) {//execute for loop, add blur background for CAPTCHA
$randcolor =imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255)); Create a background
Imagesetpixel ($im, Rand ()%70,rand ()%30, $randcolor); Draw a single element
}
Imagepng ($im); Generate PNG images
Imagedestroy ($im); Destroying images
?>

Note: PHP needs to be configured to perform related methods.

Operating effect:

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.