For a website, you will definitely need a page that provides validation functionality. Then we need to consider the application of the verification code in the verification page now. We're going to give you a detailed explanation of the
prepare a page to display and submit a PHP verification code
- Php
-
- @header ("content-type:text/html; CharSet = UTF -8 ");
-
- Open session
-
- Session_Start ();
-
- ?>
-
- < HTML >
-
- < Head >
-
- < Meta http-equiv="Content-type" Content="text/ html Charset=utf-8 " />
-
- < title > PHP Verification code example title>
-
- Head >
-
- < Body >
-
- Verification Code: <br/>
-
- < iframe id="iimg" height=" width = - src="img.php" frameborder="0" > IFrame >
-
- < BR />
-
- < input type= button value="Can't see, change one" onclick = "iimg.location.reload ();" >
-
- < BR >
-
- < form action="validate.php" method="POST" >
-
- Enter the verification code: <input name="Imgid" style="width:60" >
-
- < input type="Submit" value="OK">
-
- form >
-
- Body >
-
- HTML >
Second, the following is the PHP code generation page, the page is called on the first page
- Php
-
- Header ("Content-type:image/gif");
-
- Session_Start ();
-
- The verification code is a random character, the following is the algorithm
-
- $randval;
-
- For ($i=0; $i<7; $i + +) {
-
- $ Randstr = Mt_rand (Ord (' A '), Ord (' Z '));
-
- Srand (Double) microtime () *1000000);
-
- $ RANDV = Mt_rand (0,10);
-
- if ($randv%2==0) {
-
- $ Randval. = Mt_rand (0,10);
-
- }else{
-
- $ Randval. = CHR ($RANDSTR);
-
- }
-
- }
-
- Register PHP verification code to session
-
- Session_register ($randval);
-
- Here is the drawing of the Verification Code map
-
- $ Height = - ;//Graph High
-
- $ width = - ;//Graph width
-
- $ im = Imagecreatetruecolor ($width, $height);
-
- $ White = imagecolorallocate ($im, 255, 255, 255);
-
- $ Blue = imagecolorallocate ($im, 0, 0, 64);
-
- Imagefill ($im, 0, 0, $white);
-
- Srand (Double) microtime () *1000000000);
-
- Imageline ($im, Mt_rand (0, $width/3), Mt_rand (0, $height/3), Mt_rand ($width/3, $width), Mt_rand ($height/3, $height), $ Blue);
-
- Srand (Double) microtime () *1000000);
-
- Imageline ($im, Mt_rand ($width/3, $width), Mt_rand (0, $height/3), Mt_rand (0, $width/3), Mt_rand (0, $height/3), $blue);
-
- Srand (Double) microtime () *1000000);
-
- Imagestring ($im, Mt_rand (0, $width-strlen ($randval) *), Mt_rand (0, $height -12), $randval, $blue);
-
- Imagegif ($im);
-
- Imagedestroy ($im);
-
- /*
-
- It is important to note that in order to support the above drawing functions, we must load the GD2 graphics processing library in PHP, which can be modified in the php.ini file.
-
- ; extension = PHP_GD2 . DLL
-
- For
-
- extension = PHP_GD2 . DLL
-
- That opens the GD2 library.
-
- */
-
- ?>
Third, this is the verification page, indicating whether PHP verification code through verification
- php @header ("content-type:text/html; CharSet = UTF -8 ");
-
- Open session
-
- Session_Start ();
-
- Get user-entered verification code and convert to uppercase
-
- $ Imgid_req = $_request[' Imgid '];
-
- $ Imgid_req = Strtoupper ($imgId _req);
-
- Verify that the string is registered with the session variable
-
- if (session_is_registered ($imgId _req)) {
-
- echo " <font color= blue > verified! font> ";
-
- } else {
-
- echo " <font color= red > validation Error! font> ";
-
- }
-
- Close session to clear all registered variables
-
- Session_destroy ();
-
- ?>
http://www.bkjia.com/PHPjc/446325.html www.bkjia.com true http://www.bkjia.com/PHPjc/446325.html techarticle for a website, you will definitely need a page that provides validation functionality. Then we need to consider the application of the verification code in the verification page now. We're going to be here for everyone .