Browse Source

PHP 8 captcha fix

Sebijk 3 years ago
parent
commit
9efe3f0cfd
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/serverlib/safecode.class.php

+ 8 - 1
src/serverlib/safecode.class.php

@@ -142,8 +142,15 @@ class BMCaptchaGenerator
 			$xArea = $this->letterW - $w;
 			$xArea = $this->letterW - $w;
 			$yArea = $this->letterH - $h;
 			$yArea = $this->letterH - $h;
 
 
+			if($xArea < 0) { // Workaround for PHP 8, detecting if xArea is negative
+				$x_mtrand = mt_rand($xArea/2, ($xArea/2)*-1);
+			}
+			else {
+				$x_mtrand = mt_rand(($xArea/2)*-1, $xArea/2);
+			}
+
 			$x = max($this->borderSpacing, $this->borderSpacing *2 + $i*$this->letterW
 			$x = max($this->borderSpacing, $this->borderSpacing *2 + $i*$this->letterW
-					+ @mt_rand(($xArea/2)*-1, $xArea/2));
+					+ $x_mtrand);
 			$y = ($this->h-2*$this->borderSpacing)/2 - $h/2
 			$y = ($this->h-2*$this->borderSpacing)/2 - $h/2
 					+ @mt_rand(($yArea/2)*-1, $yArea/2);
 					+ @mt_rand(($yArea/2)*-1, $yArea/2);