【问题标题】:Fatal error: Call to undefined function - codeigniter致命错误:调用未定义的函数 - codeigniter
【发布时间】:2012-02-27 17:51:27
【问题描述】:

我得到这个错误,我不知道为什么。

我有一个产生随机字符的函数

function randomString($length) {
        $len = $length;
        $base = 'ABCDEFGHIJKLMNOPQRSTWXYZabcdefghıjklmnoprstwxyz123456789';
        $max = strlen($base) - 1;
        $activatecode = '';
        mt_srand((double) microtime() * 1000000);
        while (strlen($activatecode) < $len + 1)
            $activatecode.=$base(mt_rand(0, $max));

        return activatecode;
    }

我在

中调用了这个函数
public function kayitBasarili() {
        $this->load->view('kayitBasarili');

        $username = $this->input->post('username');
        $email = $this->input->post('email');
        $password = $this->input->post('password');

        $data = array();

        $data['username'] = $username;
        $data['email'] = $email;
        $data['password'] = $password;

        **$activationCode = $this->randomString(10);** 

        $this->load->view('kayitBasarili', $data);
        $this->kayitmodel->uyeEkle($username, $email, $password,$activationCode);
    }

为什么会出现这个错误?

【问题讨论】:

  • 函数周围的** 是怎么回事?很确定这会导致问题
  • 它是粗体功能,但在代码视图中不起作用:)
  • Mert,您仍然需要返回$activatecode。 :-) 为什么不直接使用substr( md5( microtime() . 'somesalt' ), 0, 10)
  • 激活码一定要用md5吗?

标签: php codeigniter


【解决方案1】:

看看这一行:

$activatecode.=$base(mt_rand(0, $max)); // Your calling the string as a function

应该是:

$activatecode.=$base{mt_rand(0, $max)};

$activatecode.=$base[mt_rand(0, $max)];

【讨论】:

  • 来自 PHP 手册“注意:也可以使用大括号访问字符串,如在 $str{42} 中,用于相同目的。但是,此语法已被弃用为PHP 5.3.0 的版本。请改用方括号,例如 $str[42]。"
【解决方案2】:

线

$activatecode.=$base(mt_rand(0, $max));

调用名称为$base='ABCDEFGHIJKLMNOPQRSTWXYZabcdefghıjklmnoprstwxyz123456789'内容的函数会报错;

【讨论】:

  • 顺便说一句,索引运算符是[] 而不是(),您需要返回$activatecode(带有$)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-10
  • 2019-11-10
  • 1970-01-01
  • 2013-10-28
  • 1970-01-01
相关资源
最近更新 更多