This tutorial takes advantage of jquery's Ajax to implement a pre-validation operation without refreshing the jquery php captcha code.
This tutorial takes advantage of jquery's Ajax to implement a pre-validation operation for a code that does not flush the jquery PHP tutorial captcha.
Call this page and generate a CAPTCHA picture if the following formula is true
if ($_get[' action ']== ' Verifycode ') {
Rand_create ();
}
Verification Code Picture Generation
function Rand_create () {
Notifies the browser that a PNG image will be exported
Header (' content-type:image/png ');
Get the random number generator seed ready.
Srand (Double) microtime () *1000000);
Prepare the relevant parameters for the picture
$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 Identifiers
Start drawing
Imagefill ($im, 0,0, $gray);
while (($randval =rand ()%100000) <10000); {
Drawing a four-bit integer verification code into a picture
Session_Start ();
$_session[' login_check_num '] = $randval;
Imagestring ($im, 5, 3, $randval, $black);
}
adding interfering 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 validation Picture
Imagepng ($im);
Destroy image identifiers
Imagedestroy ($im);
}
?>
The CAPTCHA code shown on the static page is:
Verification Code:
The Ajax validation code for the jquery section is:
$.post ("session.php",
{reg_code:$ ("#reg_code"). Val ()},
function (data) {
if (data = = = "1") {
Do ...
}else{
Do ...}
}
);
The PHP page that assists with Ajax validation is named Session.php, whose code is:
session_start ();
Inspection 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.com true http://www.bkjia.com/PHPjc/445429.html techarticle This tutorial takes advantage of jquery's Ajax to implement a pre-validation operation without refreshing the jquery php captcha code. This tutorial mainly uses jquery Ajax to implement the non-flush jquery PHP Tutorial Verification code Generation ...