的HTML /应用程序/ RandomCode.php
<?php
namespace App;
use \Carbon\Carbon;
class RandomCode
{
public function random_str($length, $keyspace)
{
$str = '';
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$str .= $keyspace[random_int(0, $max)];
}
return $str;
}
}
的HTML /公共/ index.php的
include($_SERVER['DOCUMENT_ROOT'].'/../app/RandomCode.php');
$code = new RandomCode();
$code->random_str(10, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
我认为这一切都是正确的,但我收到此错误:PHP Fatal error: Class 'RandomCode' not found in /var/www/html/public/index.php on line 27
我尝试了var_dump(file_exists($_SERVER['DOCUMENT_ROOT'].'/../app/RandomCode.php'));
,我收到了true
我做错了什么?
答案 0 :(得分:0)
我在PHP 5.X中使用random_int
函数而没有该函数所需的库。我已使用https://github.com/paragonie/random_compat/releases