Created
March 15, 2018 05:48
-
-
Save Anan5a/1bbf276d9d5a8de0cbcecf7dca02490f to your computer and use it in GitHub Desktop.
Super Simple Captcha script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* | |
*Author github.com/Anan5a | |
*Description Simple Captcha generator script | |
*/ | |
//require_once './Fnc.php'; //application specific | |
define('CODESTR','012ABC3456789DEFGHIJKLMNOPQRSTUVWXYZ'); | |
$font = './X51-Outline.ttf'; | |
$hash = $_GET['key']; | |
if (!is_array($_SESSION['captcha'])) { | |
$_SESSION['captcha']=[]; | |
} | |
if (!array_key_exists($hash, $_SESSION['captcha'])) { | |
//assign values | |
$str = str_shuffle(CODESTR); | |
$code = substr($str, 0, rand(3, 6)); | |
$validity = time()+360; | |
//set values | |
$_SESSION['captcha'][$hash] = [ | |
'code'=>$code, | |
'validity'=>$validity, | |
]; | |
//draw captcha | |
$image = imagecreatetruecolor(200, 50); | |
$im_color = imagecolorallocate($image, 255, 255, 255); | |
imagefilledrectangle($image, 0, 0, 200, 50, $im_color); | |
$pixel = imagecolorallocate($image, 0, 0, 255); | |
for ($i = 0; $i < 1000 ;$i ++) { | |
imagesetpixel($image, rand() %200, rand() %50, $pixel); | |
} | |
$txt_color = imagecolorallocate($image, 0, 0, 0); | |
imagettftext($image, 30, (rand(-5, 5)), 10, 40, $txt_color, $font, $code); | |
imagepng($image); | |
$im2 = $image; | |
imagedestroy($image); | |
echo $image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment