Welcome Guest, Not a member yet? Register   Sign In
I'm complete new with CodeIgniter and need help
#1

[eluser]Azraf[/eluser]
Hi,
I'm complete new in CI and need your advise/help in 2 field. This post contain the first one.

1. I've to implement session for Login into database and also need to setup a cookie for the remember me check box.

Code:
function loginCheck ()
    {
            $id = $this->input->post('id', true);
            $uName = $this->input->post('a_name', true);
            $password = $this->input->post('password', true);
            $this->load->model($this->config->item('loginCheck'),'Login_model',TRUE);
            $result = $this->Login_model->loginCheck($uName, $password);
            if ($result)
            {
                $newdata = array(
                   'user_id'  => $result->a_id,
                   'logged_in' => TRUE
               );

            $this->session->set_userdata($newdata);    
            $rem_me=$this->input->post('remember_me',true);
            if ($rem_me==true)
            {
                $this->load->helper('cookie');
                $bhr_cookie = array(
                               'name'   => 'bhr_cookie',
                               'logged_in'  => TRUE,
                               //set for 7 days
                       'expire' => '604800',
                               'domain' => 'myDomain.com',
                               'path'   => 'directoryPath/',
                               'prefix' => 'login_',
                                   );

                set_cookie($bhr_cookie);
            }      
//            $this->load->view('person/personList');        
            redirect('person/index');    
            }
            else
            {
                $data= array();
                $data['mainContent'] = "Your Login username / password  does not match. Please try again.";
                $data['homeTitle'] = 'Welcome';
                $this->load->view('v-login',$data);
                
            }                
        
    }

And in my Login model:

Code:
function loginCheck($uName,$password)
    {
        $this->db->select ( '*' );
        $this->db->from ( 'ci_user_admin' );
        $this->db->where ( 'a_name', $uName );
        $this->db->where ( 'password', md5 ( $password ) );
        $resultSet = $this->db->get ();
        return $resultSet->row ();    
    }

And for authentication verification, I've use in other controller:
Code:
if (($this->session->userdata('logged_in') != TRUE)|| empty($_COOKIE['bhr_cookie']))
       {
           redirect('login/logout');      
       }


Again, I'm complete new to CI, and also learning php, therefore i know I'm doing it as novice, and am here to learn something from you.

N.B. My script was working fine before I try the remember me (cookie), with session in database. But after I try to combine the session with database and cookie both, I cant handle it. Therefore, need help from you.
#2

[eluser]Azraf[/eluser]
Here is my login form:
Code:
]
<div id="login-form">
&lt;form name="login_user" method="post" action="&lt;?=base_url()?&gt;login/loginCheck" &gt;
<div align="center" class="required">
    &lt;?
        if(isset($_SESSION['message']))
        {
            echo $_SESSION['message'];
            unset($_SESSION['message']);
        }
    ?&gt;
</div>
<table align="center">
    <tr>
        <td>
        User Name:
        </td>
        <td>
        &lt;input type="text" name="a_name" id="a_name" realname="User Name" /&gt;
        </td>
    </tr>
    <tr>
        <td>
        Password:
        </td>
        <td>
        &lt;input type="password" name="password" realname="password" /&gt;
        </td>
    </tr>
     <tr>
        <td>&lt;input type="checkbox" id="remember_me" name="remember_me" /&gt;
        </td>
        <td>Remember Me
        </td>

    </tr>
    <tr>
        <td colspan="2">
        &lt;input type="submit" name="submit" value="Login" /&gt;
        </td>
    </tr>
</table>
&lt;/form&gt;
</div>




Theme © iAndrew 2016 - Forum software by © MyBB