php - Session in codeigniter model View Controller -


when login success redirect home page.

after set session in login , view page, when refresh same page redirect in login page, whats reason , please provide solution problem?

controller

public function login() {      $email = $this->input->post('email');      $password = md5($this->input->post('password'));      $result = $this->search_model->login($email, $password);      if($result !='') {          $this->session->set_userdata('user_id', $email);         $seid = $this->session->userdata('user_id');      }      if ($seid=='') {          //echo ($seid);          $this->index();      } else {          $this->view();      }  }    public function view() {      $seid = $this->session->userdata('user_id');     $data['result']=$this->search_model->getall($seid);     $this->load->view('pagination_view',$data);  } 

model

function login($email, $password) {        $this->db->where("email", $email);     $this->db->where("password", $password);     $query=$this->db->get("tbl_reg");      return $query->result_array();     } 

view

<?php if(!$this->session->userdata('user_id')) {     redirect(base_url().'search/login'); } else { } ?> 

two problems, first architectural second causing problem. first should not redirecting in view. should in controller loads home page (or other pages). shouldn't view if don't belong there.

the second problem if($result!=''). won't work. $result array. use if(!empty($result)) or if(count($result)!==0) or similar.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -