2018-01-09 02:09:07 +03:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @package Kleeja
|
2020-04-11 22:45:48 +02:00
|
|
|
* @copyright (c) 2007 Kleeja.net
|
2018-01-09 02:09:07 +03:00
|
|
|
* @license ./docs/license.txt
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
// Fix bug with path of font When using versions of the GD library lower than 2.0.18
|
|
|
|
|
if (function_exists('putenv'))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
2019-05-03 23:52:08 +03:00
|
|
|
@putenv('GDFONTPATH=' . realpath('.'));
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
2019-05-03 23:52:08 +03:00
|
|
|
elseif (function_exists('ini_set'))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
2019-05-03 23:52:08 +03:00
|
|
|
@ini_set('GDFONTPATH', realpath('.'));
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
// When any body request this file , he will see an image ..
|
2018-01-09 02:09:07 +03:00
|
|
|
kleeja_cpatcha_image();
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//this function will just make an image
|
|
|
|
|
//source : http://webcheatsheet.com/php/create_captcha_protection.php
|
|
|
|
|
//
|
|
|
|
|
function kleeja_cpatcha_image()
|
|
|
|
|
{
|
2019-05-03 23:52:08 +03:00
|
|
|
//Let's generate a totally random string using md5
|
|
|
|
|
$md5_hash = md5(rand(0, 999));
|
|
|
|
|
|
|
|
|
|
//I think the bad things in captcha is two things, O and 0 , so let's remove zero.
|
|
|
|
|
$security_code = str_replace('0', '', $md5_hash);
|
|
|
|
|
|
|
|
|
|
//We don't need a 32 character long string so we trim it down to 5
|
|
|
|
|
$security_code = substr($security_code, 15, 4);
|
|
|
|
|
|
|
|
|
|
//Set the session to store the security code
|
|
|
|
|
$_SESSION['klj_sec_code'] = $security_code;
|
|
|
|
|
|
|
|
|
|
//Set the image width and height
|
|
|
|
|
$width = 150;
|
|
|
|
|
$height = 25;
|
|
|
|
|
|
2022-07-28 15:52:08 +02:00
|
|
|
//Generate a random number of lines to make the image dirty
|
2024-10-07 17:15:05 +01:00
|
|
|
$lines = rand(3, 5);
|
2022-07-28 15:52:08 +02:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//Create the image resource
|
|
|
|
|
$image = imagecreate($width, $height);
|
|
|
|
|
|
|
|
|
|
//We are making three colors, white, black and gray
|
|
|
|
|
$white = imagecolorallocate($image, 255, 255, 255);
|
|
|
|
|
$black = imagecolorallocate($image, rand(0, 100), 0, rand(0, 50));
|
|
|
|
|
$grey = imagecolorallocate($image, 204, 204, 204);
|
|
|
|
|
|
|
|
|
|
//Make the background black
|
|
|
|
|
imagefill($image, 0, 0, $black);
|
|
|
|
|
|
|
|
|
|
//options
|
|
|
|
|
$x = 10;
|
|
|
|
|
$y = 14;
|
|
|
|
|
$angle = rand(-7, -10);
|
|
|
|
|
|
|
|
|
|
//Add randomly generated string in white to the image
|
|
|
|
|
if (function_exists('imagettftext'))
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// We figure a bug that happens when you add font name without './' before it ..
|
|
|
|
|
// he search in the Linux fonts cache , but when you add './' he will know it's our font.
|
|
|
|
|
//
|
2019-05-18 01:47:17 +03:00
|
|
|
imagettftext($image, 16, $angle, rand(50, $x), $y+rand(1, 3), $white, dirname(__FILE__) . '/arial.ttf', $security_code);
|
2024-10-07 17:15:05 +01:00
|
|
|
//imagettftext ($image, 7, 0, $width-30, $height-4, $white,'./arial.ttf', 'Kleeja');
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
imagestring($image, imageloadfont(dirname(__FILE__) . '/arial.gdf'), $x+rand(10, 15), $y-rand(10, 15), $security_code, $white);
|
2019-05-03 23:52:08 +03:00
|
|
|
//imagestring ($image, 1, $width-35, $height-10, 'Kleeja', ImageColorAllocate($image, 200, 200, 200));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Throw in some lines to make it a little bit harder for any bots to break
|
2024-10-07 17:15:05 +01:00
|
|
|
imagerectangle($image, 0, 0, $width-1, $height-1, $grey);
|
|
|
|
|
|
|
|
|
|
for ($i=0; $i<$lines; $i++)
|
|
|
|
|
{
|
|
|
|
|
imageline($image, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), $grey);
|
2022-07-28 15:52:08 +02:00
|
|
|
}
|
2019-05-03 23:52:08 +03:00
|
|
|
|
|
|
|
|
|
2022-07-28 15:52:08 +02:00
|
|
|
//Tell the browser what kind of file is come in and prevent client side caching
|
2024-10-07 17:15:05 +01:00
|
|
|
header('Expires: Wed, 1 Jan 1997 00:00:00 GMT');
|
|
|
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
|
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
|
|
|
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
|
|
|
|
header('Pragma: no-cache');
|
2022-07-28 15:52:08 +02:00
|
|
|
header('Content-Type: image/png');
|
2019-05-03 23:52:08 +03:00
|
|
|
|
|
|
|
|
//Output the newly created image in jpeg format
|
|
|
|
|
imagepng($image);
|
|
|
|
|
|
|
|
|
|
//Free up resources
|
2025-12-06 15:51:41 +01:00
|
|
|
// imagedestroy() has no effect since PHP 8.0
|
|
|
|
|
// Only call it for PHP < 8.0 where it actually frees memory
|
|
|
|
|
if (PHP_VERSION_ID < 80000)
|
|
|
|
|
{
|
|
|
|
|
imagedestroy($image);
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<--- EOF
|