php - Codeigniter show controller if session exists -
i'm new codeigniter , learn it.
i got 2 controllers, 1st 1 called main , responds user registration / login second 1 called todo , shows todo list.
now if access localhost/list website opens page, write session logic test if user logged in?
my controller todo
defined('basepath') or exit('no direct script access allowed'); class lists extends ci_controller { public function index() { $this->load->view('lists');} }
how display using session:
if($this->session->userdata('is_logged_in') == 1)
or have put session logic before each function?
you put session $this->session->userdata('is_logged_in')
condition in __construct()
like :
<?php class lists extends ci_controller { public function __construct() { parent::__construct(); if($this->session->userdata('is_logged_in') != 1) { //redirect code here } } public function index() { $this->load->view('lists');} } }
Comments
Post a Comment