1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- require_once(realpath(dirname(__FILE__)).'/config.php');
- require_once(PATH_PHP.'security.php');
- function generate_captcha(){
- $captcha = substr(md5(rand()),0,15);
- $_SESSION['captcha'] = $captcha;
-
- $width = 165;
- $height = 20;
-
- $image = ImageCreate($width, $height);
-
- $white = ImageColorAllocate($image, 255, 255, 255);
- $black = ImageColorAllocate($image, 0, 0, 0);
- $grey = ImageColorAllocate($image, 204, 204, 204);
-
- ImageFill($image, 0, 0, $black);
-
- ImageString($image, 3, 30, 3, $captcha, $white);
-
- ImageRectangle($image,0,0,$width-1,$height-1,$grey);
- imageline($image, 0, $height/2, $width, $height/2, $grey);
- imageline($image, $width/2, 0, $width/2, $height, $grey);
-
- header("Content-Type: image/jpeg");
-
- ImageJpeg($image);
-
- ImageDestroy($image);
- exit();
- }
- function compare_captcha($captcha){
- return isset($_SESSION['captcha'])&&$captcha == $_SESSION['captcha'];
- }
- ?>
|