0
votes

i get this error i dont know why.

i have a function that produce random characters

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;
    }

and i call this function in

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);
    }

Why i get this error ? enter image description here

2
whats with the ** surrounding the function? pretty sure that would cause issues - Lawrence Cherone
it is bold function but does not work in code view :) - Mert METİN
Mert, you still need to return $activatecode. :-) And why not just use substr( md5( microtime() . 'somesalt' ), 0, 10)? - TerryE
is it necessary to use md5 for activationcode ? - Mert METİN

2 Answers

4
votes

look at this line:

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

it should be:

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

or

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

The line

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

calls the function whose name is the contents of $base = 'ABCDEFGHIJKLMNOPQRSTWXYZabcdefghıjklmnoprstwxyz123456789'hence the error;