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 = 50;
-
- $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);
-
- imagettftext($image,13,-7,5,20,$white,realpath(dirname(__FILE__)).'/../css/fonts/FiraMono/FiraMono-Bold.ttf',$captcha);
-
- ImageRectangle($image,0,0,$width-1,$height-1,$grey);
- imageline($image,0,0,$width,$height,$grey);
- imageline($image,$width,0,0,$height,$grey);
-
- header("Content-Type: image/jpeg");
-
- ImageJpeg($image);
-
- ImageDestroy($image);
- exit();
- }
- function compare_captcha($captcha){
- return isset($_SESSION['captcha'])&&$captcha == $_SESSION['captcha'];
- }
- ?>
|