•新建一个PHP文件captcha_code_file.php
代码如下 | 复制代码 |
//首先开启session session_start(); //定义前台显示验证码长&宽 $image_width = 120; $image_height = 40; $characters_on_image = 6; $font = './monofont.ttf'; //The characters that can be used in the CAPTCHA code. $i = 0; $font_size = $image_height * 0.75; /* setting the background, text and noise colours here */ $arr_text_color = hexrgb($captcha_text_color); $arr_noice_color = hexrgb($captcha_noice_color); /* generating the dots randomly in background */ /* generating lines randomly in background of image */ /* create a text box and add 6 letters code in it */ /* Show captcha image in the page html page */ function hexrgb ($hexstr) return array("red" => 0xFF & ($int >> 0x10), |
调用页面显示验证码页面index.php
代码如下 | 复制代码 |
<?php session_start(); if(isset($_REQUEST['Submit'])){ // code for check server side validation if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { $msg="您输入的验证码有误,请重新输入!"; }else{ echo "您输入的是正确的!"; // Captcha verification is Correct. Final Code Execute here! } } ?> <style type="text/css"> <form action="" method="post" name="form1" id="form1" > |