CodeIgniter Forums
login problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: login problem (/showthread.php?tid=182)



login problem - bobykurniawan - 11-08-2014

Hey, i try to implementing cookies for login and save it to database. But i've a problem with this error.

Quote:A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: core/Input.php

Line Number: 286

Success to login but if i disable the redirect, that error is showing and able to save into logindata

This my controller for login

PHP Code:
public function ceklogin()
    {
        
$this->form_validation->set_rules('username''Username''required');
        
$this->form_validation->set_rules('key''Password''required');
        
$this->form_validation->set_error_delimiters('<div class="alert alert-danger">''</div>');
        if (
$this->form_validation->run() == FALSE)
        {
        
$this->loginform();
        }
        else
        {
            
$vUsername         $this->input->post('username');
            
$vPassword         md5($this->input->post('key'));
            
$tbl='user';
            
$fieldpilih='*'
            
$fieldkondisi=array('username'=>$vUsername,'password'=>$vPassword); 
            
$hasil $this->modeldonatur->pilihdata($tbl,$fieldkondisi,$fieldpilih);                
            if(
$hasil!=null)
            {                
                
$tabel                    'logindata';
                
$kondisi['username']     = $vUsername;
                
$this->modeldonatur->hapusdata($tabel,$kondisi);
                
$vToken                $this->donaturlib->randstring();
                
$tabel                 'logindata';
                
$isi['username']    = $vUsername;
                
$isi['sesi']        = $vToken;
                
$isi['waktu']        = date("YmdHis");
                
$this->modeldonatur->simpandata($tabel,$isi);
//Saving cookie                
                
$vCookie1['sname']     = 'dnt_user_cookie';
                
$vCookie1['value']     = $vUsername;
                
$vCookie1['expire'] = '100';
                
$this->input->set_cookie($vCookie1);
//saving token
                
$vCookie2['name']    = 'dnt_sesi_cookie';
                
$vCookie2['value']     = $vToken;
                
$vCookie2['expire']     = '100';
                
$this->input->set_cookie($vCookie2);
        
//    redirect('login/nowwhere','refresh');        
            
}
        else
            {
                
$error "Username atau Password Salah";
            
//    $this->loginform($error);
            
}

        }    
    } 

My model for the proses above


PHP Code:
function pilihdata($tbl,$fieldkondisi,$fieldpilih)
{       
           return 
$this->db->select($fieldpilih)
                ->
from($tbl)
                ->
where($fieldkondisi)
                ->
get()
                ->
result();                   
}
 function 
hapusdata($tabel,$kondisi)
        {
            
$this->db->delete($tabel,$kondisi);
        }
 function 
simpandata($tabel,$isi)
        {
            
$this->db->insert($tabel,$isi);
        } 

and the randstring in my lib

PHP Code:
function randstring()
  {
    
$pass   60;
    
$allchar  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
    
mt_srand  ((double) microtime()*1000000);
    
$string   ='';
    for(
$i=0;$i<$pass;$i++)
    {
      
$string .= $allchar{mt_rand(0,strlen($allchar) - 1)};
    }
    return 
$string;
  } 

An


RE: login problem - Rufnex - 11-09-2014

Can you show the Line Number: 286 and the base of the given array.
the error tells you that you use an array within a function who needs a string.


RE: login problem - bobykurniawan - 11-09-2014

(11-09-2014, 01:28 AM)Rufnex Wrote: Can you show the Line Number: 286 and the base of the given array.
the error tells you that you use an array within a function who needs a string.

Thanks for trying help. My problem already solved.

There is a typo in saving cookies
PHP Code:
$vCookie1['sname']     = 'dnt_user_cookie'
It should be like this
PHP Code:
$vCookie1['name']     = 'dnt_user_cookie'
well, i'm a 'noob' Big Grin


RE: login problem - Rufnex - 11-09-2014

fine! ;o)


RE: login problem - Chroma - 11-14-2014

If only all bugs were that straightforward.

Smile