php - Cookie not working with Login System CodeIgniter -
i have implemented basic login scheme using codeigniter. using sessions
library command access members section. can log in , view area no problem. when delete cookies , refresh members section page can still see content. not displaying login message user.
i don't know why happening. ideas?
this site.php controller
class site extends ci_controller{ function _construct(){ parent::_construct(); $this->is_logged_in(); } function members_area(){ $this->load->view('members_area'); } function is_logged_in(){ $is_logged_in = $this->session->userdata('is_logged_in'); if(!isset($is_logged_in) || $is_logged_in != true){ echo 'you need login access page. <a href="../login">login</a>'; die(); }
} }
this login.php controller
class login extends ci_controller{ function index(){ $data['main_content'] = 'login_form'; $this->load->view('includes/template', $data); } function validate_credentials(){ $this->load->model('membership_model'); $query = $this->membership_model->validate(); if($query){//if credentials validated $data = array( 'username' => $this->input->post('username'), 'is_logged_in' => true ); $this->session->set_userdata($data); redirect('site/members_area'); } else{//if not validated re load login form $this->index(); } } function signup(){ $data['main_content'] = 'signup_form'; $this->load->view('includes/template', $data); } function create_member(){ $this->load->library('form_validation'); //field name, error message, validation rules $this->form_validation->set_rules('first_name', 'name', 'trim|required'); $this->form_validation->set_rules('last_name', 'last name', 'trim|required'); $this->form_validation->set_rules('email_address', 'email address', 'trim|required|valid_email'); $this->form_validation->set_rules('username', 'username', 'trim|required|min_length[4]'); $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[4]|max_length[32]'); $this->form_validation->set_rules('password2', 'password confirmation', 'trim|required|matches[password]'); if($this->form_validation->run() == false){ $this->signup(); } else{ //create new row in db $this->load->model('membership_model'); if($query = $this->membership_model->create_member()){ //info entered $data['main_content'] = 'signup_successful'; $this->load->view('includes/template', $data); } else{ $this->load->view('signup_form'); } } }
}
this code should executed if session not exist. found in site.php
file.
if(!isset($is_logged_in) || $is_logged_in != true){ echo 'you need login access page. <a href="../login">login</a>'; die();
any help much appreciated!
looks constructor isn't beingness called.
perhaps because needs 2 underscores, not 1 :)
function __construct(){ parent::__construct(); $this->is_logged_in(); }
php codeigniter session login session-cookies
No comments:
Post a Comment