0

How to make an automatic code generator so that I can send it to a mobile using my API then verify it after checking in php codeigniter
My one related controller looks like:

 public function print_patientdetails($id,$veri,$phone,$username) {

     if($veri == 0){
         $verifycode = "12345";   // here I need an automatic code generator function
         $result['verifycode'] = "12345";//and here need to  keep the code and pass hidden throughout the pages 
         echo $this->sendverifymsg($phone, $verifycode);
         $result['query'] = $this->panel_model->hospitaldetails($sess_id);
         $result['query1'] = $this->register_model->view_register($phone, $username);

         $this->load->view('innerheader', $result);
         $this->load->view('verify', $result);
         $this->load->view('footer', $result); 
    }else{
        $sess_id = $this->session->userdata('id');
        $result['query'] = $this->panel_model->hospitaldetails($sess_id);
        $result['query1'] = $this->register_model->edit_patient($id);
        foreach ($result['query1'] as $row)
        {
            $phone = $row->phone;
            $username = $row->userid;
            $email = $row->email;

            $this->load->view('print_patientdetail', $result);
            echo $this->sendregistermsg($phone, $username);
            echo $this->mail($email, $phone, $username); 
        }
    }
} 
Cœur
  • 37,241
  • 25
  • 195
  • 267
Nayanz
  • 35
  • 5

2 Answers2

1

Just use php uniqid() native function like this:

$verifycode = uniqid();
Mike Miller
  • 3,071
  • 3
  • 25
  • 32
0

what i understood is you just need something which can generate a random code for you. if this is purpose you can use rand(0,99999); function which generates random numbers.

Moreover if you need that this random number should not b one from already generated then you can use db to store random numbers, enter it when it generates and at the time of new generating compare it with already stored random numbers.

Imran Qamer
  • 2,253
  • 3
  • 29
  • 52
  • ...ya i need something which can generate a random code. – Nayanz Apr 02 '15 at 07:17
  • its not a problem if its already generated. but using rand (0,99999) how can generated a code in above variable "$verifycode"..can u please explain a littel bit.. – Nayanz Apr 02 '15 at 07:20
  • you welcome dear, this answer has not worked for you? you accepted and then unaccepted it ? – Imran Qamer Apr 10 '15 at 07:00
  • no problem its okay, actually the rule is accept that answer which best and fullfill your requirement because it will also helpfull for other users who will visit it. – Imran Qamer Apr 10 '15 at 07:15