找回密码
 新建账号

Discuz X 3.5 mt_rand(): Argument #2 ($max) must be greater than or equal to argument #1 ($min)

[复制链接]
php 发表于 2023/4/20 18:53 | 显示全部楼层 |阅读模式
Discuz! X 3.5 source/class/class_seccode.php 第 221 行代码错误,导致验证码不能正常显示,并且报错 mt_rand(): Argument #2 ($max) must be greater than or equal to argument #1 ($min)
  1. mt_rand(): Argument #2 ($max) must be greater than or equal to argument #1 ($min)
  2. PHP:misc.php#require(%s):0096 -> source/module/misc/misc_seccode.php#seccode->seccode->display():0187 -> source/class/class_seccode.php#seccode->seccode->image():0042 -> source/class/class_seccode.php#seccode->seccode->ttffont():0064 -> source/class/class_seccode.php#mt_rand(%f, %d):0221 -> source/class/class_seccode.php#break():0221
  3. User: uid=1; IP=102.45.217.36; RIP:102.45.217.36 Request: /misc.php?mod=seccode&update=88541&idhash=cSzjo847
复制代码
出现这个错误,是因为 PHP mt_rand($min, $max) 函数参数取值错误,正常情况下,$min 和 $max 都必须是整数,而且 $min 不能比 $max 大,修改代码可解决这个问题。
用文本编辑软件打开 并搜索定位到以下代码
  1.   $x = mt_rand($font[0]['angle'] > 0 ? cos(deg2rad(90 - $font[0]['angle'])) * $font[0]['zheight'] : 1, $this->width - $widthtotal);
复制代码
将它修改为以下代码
  1.   $qbbsXLimits = [$font[0]['angle'] > 0 ? cos(deg2rad(90 - $font[0]['angle'])) * $font[0]['zheight'] : 1, $this->width - $widthtotal];
  2.   $x = $qbbsXLimits[0] < $qbbsXLimits[1] ? mt_rand(...$qbbsXLimits) : $qbbsXLimits[0];
复制代码
保存文件即可,代码可以有多种修改方式,以上示例只是其中一种。
更多信息可以参考 PHP 官方文档
https://www.php.net/manual/en/function.mt-rand.php
https://www.php.net/manual/en/functions.arguments.php

手机版|轻松E站

GMT+8, 2024/4/26 19:23

快速回复 返回顶部 返回列表