Changeset 10448 for temp/trunk
- Timestamp:
- 2006/12/08 11:36:38 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
temp/trunk/html/test/uehara/captcha/ajax_captcha/create_image.php
r10447 r10448 1 1 <? 2 /* 3 This is PHP file that generates CAPTCHA image for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial 4 5 You may use this code in your own projects as long as this 6 copyright is left in place. All code is provided AS-IS. 7 This code is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 11 For the rest of the code visit http://www.WebCheatSheet.com 12 13 Copyright 2006 WebCheatSheet.com 14 15 */ 16 17 //Start the session so we can store what the security code actually is 2 // ¥»¥Ã¥·¥ç¥ó¥¹¥¿¡¼¥È 18 3 session_start(); 19 20 //Send a generated image to the browser 21 create_image(); 4 // ²èÁü¥¤¥á¡¼¥¸À¸À® 5 create_image(); 22 6 exit(); 23 7 24 8 function create_image() 25 9 { 26 // Let's generate a totally random string using md510 // ¥é¥ó¥À¥à¤Êʸ»úÎó¤òÀ¸À® 27 11 $md5_hash = md5(rand(0,999)); 28 // We don't need a 32 character long string so we trim it down to 512 // ʸ»úÎó¤ò£µ·å¤Ë¤¹¤ë 29 13 $security_code = substr($md5_hash, 15, 5); 30 31 //Set the session to store the security code 14 // ¥»¥Ã¥·¥ç¥ó¤ËÀ¸À®¤µ¤ì¤¿¥³¡¼¥É¤òÊݸ 32 15 $_SESSION["security_code"] = $security_code; 33 16 34 // Set the image width and height35 $width = 1 00;36 $height = 20;17 //¡¡¥¤¥á¡¼¥¸¥µ¥¤¥ºÄêµÁ 18 $width = 120; 19 $height = 30; 37 20 38 //Create the image resource39 21 $image = ImageCreate($width, $height); 40 22 41 // We are making three colors, white, black and gray23 // ¿§¤ÎÄêµÁ 42 24 $white = ImageColorAllocate($image, 255, 255, 255); 43 25 $black = ImageColorAllocate($image, 0, 0, 0); 44 26 $grey = ImageColorAllocate($image, 204, 204, 204); 45 27 46 // Make the background black47 ImageFill($image, 0, 0, $ black);28 // ÇØ·Ê¿§ 29 ImageFill($image, 0, 0, $white); 48 30 49 // Add randomly generated string in white to the image50 ImageString($image, 3, 30, 3, $security_code, $ white);51 31 // À¸À®¤·¤¿¥³¡¼¥É¤òɽ¼¨ 32 ImageString($image, 3, 30, 3, $security_code, $black); 33 /* 52 34 //Throw in some lines to make it a little bit harder for any bots to break 53 35 ImageRectangle($image,0,0,$width-1,$height-1,$grey); 54 36 imageline($image, 0, $height/2, $width, $height/2, $grey); 55 37 imageline($image, $width/2, 0, $width/2, $height, $grey); 56 38 */ 57 39 //Tell the browser what kind of file is come in 58 40 header("Content-Type: image/jpeg"); 59 60 //Output the newly created image in jpeg format 41 // jpag¤Ç½ÐÎÏ 61 42 ImageJpeg($image); 62 63 //Free up resources64 43 ImageDestroy($image); 65 44 }
Note: See TracChangeset
for help on using the changeset viewer.
