fix kcaptcha

This commit is contained in:
2025-11-08 22:41:40 +05:00
parent 3c1b25909d
commit 6544a2d2e2

View File

@@ -1,6 +1,6 @@
<?php
# KCAPTCHA PROJECT VERSION 2.1.1
# KCAPTCHA PROJECT VERSION 2.1.1 (Исправлено для PHP 8.x)
# Automatic test to tell computers and humans apart
@@ -8,17 +8,11 @@
# www.captcha.ru, www.kruglov.ru
# System requirements: PHP 4.0.6+ w/ GD
# NOTE! decomment string "function KCAPTCHA(){" and comment "function __construct(){" to complify with php below 5.0
# KCAPTCHA is a free software. You can freely use it for developing own site or software.
# If you use this software as a part of own sofware, you must leave copyright notices intact or add KCAPTCHA copyright notices to own.
# As a default configuration, KCAPTCHA has a small credits text at bottom of CAPTCHA image.
# You can remove it, but I would be pleased if you left it. ;)
# See kcaptcha_config.php for customization
class KCAPTCHA{
// generates keystring and image
public $keystring;
//function KCAPTCHA(){ // old PHP declaration
function __construct(){ // new PHP declaration
@@ -90,9 +84,12 @@ class KCAPTCHA{
for($i=0;$i<$length;$i++){
$m=$font_metrics[substr($this->keystring, $i, 1)];
$y=(($i%2)*$fluctuation_amplitude - $fluctuation_amplitude/2)*$odd
// 🛑 ИСПРАВЛЕНИЕ: Приведение к int для координаты Y
$y=(int)(
(($i%2)*$fluctuation_amplitude - $fluctuation_amplitude/2)*$odd
+ mt_rand(-round($fluctuation_amplitude/3), round($fluctuation_amplitude/3))
+ ($height-$fontfile_height)/2;
+ ($height-$fontfile_height)/2
);
if($no_spaces){
$shift=0;
@@ -104,7 +101,10 @@ class KCAPTCHA{
$opacity=$rgb>>24;
if($opacity<127){
$left=$sx-$m['start']+$x;
$py=$sy+$y;
// 🛑 ИСПРАВЛЕНИЕ: Приведение к int для координаты PY
$py=(int)($sy+$y);
if($py>$height) break;
for($px=min($left,$width-1);$px>$left-200 && $px>=0;$px-=1){
$color=imagecolorat($img, $px, $py) & 0xff;
@@ -172,8 +172,9 @@ class KCAPTCHA{
for($x=0;$x<$width;$x++){
for($y=0;$y<$height;$y++){
$sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1;
$sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10;
// 🛑 ИСПРАВЛЕНИЕ: Приведение к int для sx и sy
$sx=(int)($x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1);
$sy=(int)($y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10);
if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){
continue;
@@ -206,18 +207,18 @@ class KCAPTCHA{
$newcolor=$newcolor/255;
$newcolor0=1-$newcolor;
$newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0];
$newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1];
$newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2];
$newred=(int)($newcolor0*$foreground_color[0]+$newcolor*$background_color[0]);
$newgreen=(int)($newcolor0*$foreground_color[1]+$newcolor*$background_color[1]);
$newblue=(int)($newcolor0*$foreground_color[2]+$newcolor*$background_color[2]);
}
imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue));
}
}
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
if(function_exists("imagejpeg")){
header("Content-Type: image/jpeg");