Home > Backend Development > PHP Tutorial > php jquery verification code_PHP tutorial

php jquery verification code_PHP tutorial

WBOY
Release: 2016-07-20 11:01:45
Original
1208 people have browsed it

This tutorial mainly uses jquery's ajax to implement advance verification of jquery php verification code without refreshing. ​

This tutorial mainly uses jquery's ajax to realize the advance verification operation of the jquery php tutorial verification code code without refreshing.

//Calling this page, if the following formula is true, generate a verification code image
if($_get['action']=='verifycode'){
rand_create();
}
//Verification code image generation

function rand_create(){
//Notify the browser that png images will be output

header('content-type: image/png');

//Prepare the random number generator seed
srand((double)microtime()*1000000);
//Prepare the relevant parameters of the image
$im = imagecreate(62,20);
$black = imagecolorallocate($im, 0,0,0); //rgb black identifier
$white = imagecolorallocate($im, 255,255,255); //rgb white identifier
$gray = imagecolorallocate($im, 200,200,200); //rgb gray identifier
//Start drawing
Imagefill($im,0,0,$gray);
While(($randval=rand()%100000)<10000);{
​​​​ //Draw the four-digit integer verification code into the picture
Session_start();
$_session['login_check_num'] = $randval;
Imagestring($im, 5, 10, 3, $randval, $black);
}
//Add interference pixels
for($i=0;$i<200;$i++){
          $randcolor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70, rand()%30, $randcolor);
}
//Output verification image
Imagepng($im);
//Destroy image identifier
Imagedestroy($im);
}

?>
The verification code displayed on the static page is:

Verification code:
                                                                       The ajax verification code for the jquery part is: php jquery verification code_PHP tutorial
$.post("session.php",

{reg_code:$("#reg_code").val()},
Function(data){
If(data === "1"){
          //do...
}else{
                                                                                                                                                                    }
);

The php page that assists in ajax verification is called session.php, and its code is:

session_start(); //Check verification code

if($_post['reg_code'] == $_session['login_check_num']){
echo 1;
}else{
echo 0;
exit();
}


?>



http://www.bkjia.com/PHPjc/445429.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445429.htmlTechArticleThis tutorial mainly uses jquery's ajax to realize the advance verification operation of jquery php verification code code without refreshing. This tutorial mainly uses jquery's ajax to implement the non-refresh jquery php tutorial verification code code...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template