php - CodeIgniter 3.0.2 does not login with old code -
user_log.php (this controller file)
<?php class user_log extends ci_controller { public function __construct() { parent::__construct(); $this->load->model('user_data'); } public function index($msg = null) { $data['msg'] = $msg; $data['title'] = "my real title"; $data['heading'] = "my real heading"; $data['attribute'] = array('name' => 'process'); $data['data'] = array( 'name' => 'username', 'id' => 'username', ); $data['pass'] = array( 'name' => 'password', 'id' => 'password', ); $this->load->view('login', $data); } public function process() { // load model $this->load->model('user_data'); // validate user can login $result = $this->user_data->validate(); // verify result if(! $result){ // if user did not validate, show them login page again $msg = '<font color=red>invalid username and/or password.</font><br />'; $this->index($msg); }else{ // if user did validate, // send them members area redirect('success'); } } }
user_data.php (this model file)
<?php class user_data extends ci_model { public function __construct() { parent::__construct(); } public function validate() { $username = $this->security->xss_clean($this->input- >post('username')); $password = $this->security->xss_clean($this->input- >post('password')); $this->db->where('username', $username); $this->db->where('password', $password); $query = $this->db->get('user'); if($query->num_rows == 1) { // if there user, create session data $row = $query->row(); $data = array( 'id' => $row->id, 'username' => $row->username, 'validated' => true ); $this->session->set_userdata($data); return true; } return false; } }
login.php (this view file)
<head> <title>jotorres login screen | welcome </title> </head> <body> <div id='login_form'> <form action='<?php echo base_url();?>index.php/blog/process' method='post' name='process'> <h2>user login</h2> <br /> <label for='username'>username</label> <input type='text' name='username' id='username' size='25' /><br /> <label for='password'>password</label> <input type='password' name='password' id='password' size='25' /><br /> <input type='submit' value='login' /> </form> </div> </body> </html>
where problem of code? not working in codeigniter version 3.0.
according code provided, form action wrong.
<form action='<?php echo base_url();?>index.php/blog/process' method='post' name='process'> ^ ^
this should be
<form action='<?php echo base_url();?>index.php/user_log/process' method='post' name='process'> ^ ^
instead of blog
, should user_log
.
also not echoing error message in login page. add in login.php
may after <form>
tag.
<?= $msg ?>
Comments
Post a Comment