function vcode_encrypt($n) { return floor($n / 1000) * 1000 + ($n % 10 + floor($n / 10) % 10 + floor($n / 100) % 10) % 10 * 100 + floor($n / 100) * 7 % 10 * 10 + $n * 13 % 10; } $width = 50; $height = 24; $my_image = imagecreatetruecolor($width, $height); imagefill($my_image, 0, 0, 0xffffff); // add noise for ($c = 0; $c < 40; $c++) { $x = rand(0, $width - 1); $y = rand(0, $height - 1); imagesetpixel($my_image, $x, $y, 0x0); } $x = rand(1, 10); $y = rand(1, 10); //$rand_string = rand(1000,9999); //encrypt number: $rand_string = vcode_encrypt($_GET["vcode"]); imagestring($my_image, 5, $x, $y, $rand_string, 0xe61240); setcookie('verification_string', md5($rand_string) . 'f**k'); imagejpeg($my_image); imagedestroy($my_image); /*** For references:(For more info - http://www.thewebhelp.com/php/scripts/php-contact-form-with-image-validation/ ) //HTML part: to get the verification code image: <img src="verificationImage.php?<?php echo rand(0,9999);?>" alt="如果看不清,點擊得到新檢測點證碼" width="50" height="24"/> //PHP Validation Part: to check to see if verificaton code was correct: if(md5($verif_box).'f**k' == $_COOKIE['verification_string']){ then proceed registeration. } ***/
</dd> <dd class="tips"><span id="emailmsg" class="d_err"></span></dd> </dl> <dl class="cc"> <dt>驗 證 碼:<font color="red">*</font></dt> <dd> <input onKeyUp="out_chkcode();" onBlur="out_chkcode();" name="Verifycode" type="text" id="Verifycode" class="input" style="width:60px; float:left; margin-right:7px;" maxlength="6"> <img id="showVerify" onClick="getNewVerifyCode();" src="php/verificationImage.php?vcode=<?php echo $vcode = rand(1000, 9999); ?> " alt="檢測點證碼" width="50" height="24"/> <?php setcookie('verification_string', md5(vcode_encrypt($vcode)) . 'f**k'); ?> </dd> <dd class="tips"><span id="chkcodemsg" class="d_err"></span></dd> </dl> <!--<dl> </dl class="cc" style="height:50px;"> <dt> </dt> <dd><input type="checkbox" name="membership_checkbox"/>我要申請成為貴賓會員</dd> <dd> </dd>--> <dl class="cc" style="height:50px;"> <dt> </dt> <dd> <input type="submit" value="現在立即註冊" style="width:100%; height:50px; background-color:#4B92DE;font-size:20px;color:white;font-weight:bold;"/>