html/app/tandycode.php
<?php
namespace App;
use CarbonCarbon;
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/public/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
我做错了什么?
i在php 5.x中使用random_int
功能,而该功能不需要库。我已经使用https://github.com/paragonie/random_compat/releases