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 outputheader('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:
$.post("session.php",
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();
}
?>