Welcome Guest, Not a member yet? Register   Sign In
login problem
#1
Sad 

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
Reply
#2

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.

Reply
#3

(This post was last modified: 11-09-2014, 04:15 AM by bobykurniawan.)

(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
Reply
#4

fine! ;o)

Reply
#5

If only all bugs were that straightforward.

Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB