iam trying to make a simple login session , but i get redirected to login page, here is my Login.php controller.
> <?php class Login extends CI_Controller
{ function __construct()
{
> parent::__construct();
if($this->session->userdata('admin'))
> redirect('admin/dashboard');
}
function index()
{
> $this->load->view('admin/login', $data);
} function verify() {
> //username:admin password:123456
$this->load->model('admin');
> $check = $this->admin->validate();
if($check) {
> $this->session->set_userdata('admin','1');
> redirect('admin/dashboard');
}
else
{
>
redirect('admin'); } }
>
>
>
> }
and here is my Dashboard.php controller which the ademin would redurect if the username and password are correct
<?php
class Dashboard extends CI_Controller
{
function __construct()
{
parent::__construct();
if(!$this->session->userdata('admin'))
redirect('admin');
}
function index()
{
$this->load->view('admin/dashboard');
}
function logout()
{
$this->session->sess_destroy();
redirect('admin');
}
}
and here is database.php
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'ASGB-test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
)
;
here is my autoload.php, i activate database and session libraries here
$autoload['libraries'] = array('database','session');
here is routes.php, welcome controller is basically the original codeigniter welcome view, and i define the admin rout as well
$route['default_controller'] = 'welcome';
$route['admin'] = 'admin/login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
here is Admin_model.php
<?php
class Admin_model extends CI_Model
{
function validate()
{
$arr['username'] = $this->input->post('Username');
$arr['password'] = md5($this->input->post('Password'));
return $this->db->get_where('admins',$arr)->row();
}
}
I am sure im entering correct password and username , but it just redirect me to the login page
$datain$this->load->view('admin/login', $data);- KUMAR