Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 随机串码点火器_Php_Codeigniter - Fatal编程技术网

Php 随机串码点火器

Php 随机串码点火器,php,codeigniter,Php,Codeigniter,在我的控制器中,我试图从函数run_key()生成一个随机字符串。我已经尝试过了,但没有生成随机字符串。如果我像这个例子那样做,它会起作用 public function index () { $this->load->helper('string'); // Currently Hard Coded Key $data['encryption_key'] = random_string(&^)(*&sf465sd4fsd6^%1321^%#, 128);

在我的控制器中,我试图从函数run_key()生成一个随机字符串。我已经尝试过了,但没有生成随机字符串。如果我像这个例子那样做,它会起作用

public function index () {
  $this->load->helper('string');
  // Currently Hard Coded Key
  $data['encryption_key'] = random_string(&^)(*&sf465sd4fsd6^%1321^%#, 128);

  //Also Tried
  $data['encryption_key'] = random_string($this->run_key(), 128);
  $data['encryption_key'] = random_string($len, 128);
}
我正在尝试获取它,以便可以从我的函数run key()中生成一个随机字符串

在同一控制器上

public function run_key() {

$chars = array(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?', '!', '@', '#',
'$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}', '|', ';', '/', '=', '+'
);

shuffle($chars);

$num_chars = count($chars) - 1;
$token = '';

for ($i = 0; $i < $len; $i++){
$token .= $chars[mt_rand(0, $num_chars)];
}

return $token;
}
}
公共函数运行\u键(){
$chars=数组(
‘a’、‘b’、‘c’、‘d’、‘e’、‘f’、‘g’、‘h’、‘i’、‘j’、‘k’、‘l’、‘m’,
“n”、“o”、“p”、“q”、“r”、“s”、“t”、“u”、“v”、“w”、“x”、“y”、“z”,
‘A’、‘B’、‘C’、‘D’、‘E’、‘F’、‘G’、‘H’、‘I’、‘J’、‘K’、‘L’、‘M’,
“N”、“O”、“P”、“Q”、“R”、“S”、“T”、“U”、“V”、“W”、“X”、“Y”、“Z”,
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?', '!', '@', '#',
'$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}', '|', ';', '/', '=', '+'
);
洗牌($chars);
$num_chars=计数($chars)-1;
$token='';
对于($i=0;$i<$len;$i++){
$token.=$chars[mt_rand(0,$num_chars)];
}
返回$token;
}
}

首先,您的函数助手使用错误

示例用法:

回送随机字符串('alnum',16)

第一个参数指定字符串的类型,第二个参数指定长度。以下选项可用:
alpha、alumum、numeric、nozero、unique、md5、encrypt和sha1

因为你正在滚动你自己的随机字符串。你真的不需要这样做

其次,在for循环中,
$len
未声明。也许你指的是在那个地方的
$num\u chars
,而不是
$len

public function run_key() {

    $chars = array(
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
        'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?', '!', '@', '#',
        '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}', '|', ';', '/', '=', '+'
    );

    shuffle($chars);

    $num_chars = count($chars) - 1;
    $token = '';

    for ($i = 0; $i < $num_chars; $i++){ // <-- $num_chars instead of $len
        $token .= $chars[mt_rand(0, $num_chars)];
    }

    return $token;
}
公共函数运行\u键(){
$chars=数组(
‘a’、‘b’、‘c’、‘d’、‘e’、‘f’、‘g’、‘h’、‘i’、‘j’、‘k’、‘l’、‘m’,
“n”、“o”、“p”、“q”、“r”、“s”、“t”、“u”、“v”、“w”、“x”、“y”、“z”,
‘A’、‘B’、‘C’、‘D’、‘E’、‘F’、‘G’、‘H’、‘I’、‘J’、‘K’、‘L’、‘M’,
“N”、“O”、“P”、“Q”、“R”、“S”、“T”、“U”、“V”、“W”、“X”、“Y”、“Z”,
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?', '!', '@', '#',
'$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}', '|', ';', '/', '=', '+'
);
洗牌($chars);
$num_chars=计数($chars)-1;
$token='';

对于($i=0;$i<$num_chars;$i++){//在你的
for
循环中,
$len
是未声明的。也许你的意思是
$num\u chars
要放在那个地方,而不是
$len
我已经按照《用户指南》做了,但是运行key不起作用。我必须使用你推荐的alpha、alumn、num、nozero、unique、md5、encrypt和sha1,而不是我认为的额外脚本。@acoderslife什么意思是不工作?。这是我在函数索引中将其添加到$data['encryption\u key']=''时的代码示例。这种方式可以工作$data['encryption\u key']=random\u string('alpha',128);但不确定如何将run key函数添加到$data['encryption\u key']
$data['encryption\u key']=$this->run u key()
使用函数
substr($this->run_key(),0,31)
或将其设置为
31,而不是循环上的
$num_chars