art art - 7 months ago 43
PHP Question

Session redirect to home when id is null with codeigniter 3.0

Here is my code in controller:

$newdata = array(
'uid' => $usern,
'ou' => $filter
);

$this->session->set_userdata($newdata);
$this->masterpage->view('User/homeuser');


And here is my code in views:

<?php

$user = $this->session->all_userdata();

if ($this->session->userdata('uid')=='') {
redirect('main/main', 'refresh');
}

?>


However when I type link:
http://localhost/[system_name]/index.php/[controller_name]/index


(link to show when uid is null, the page should redirect to main)

Only blank page is appearing. It seems it didn't redirect to the main/main page. Can anyone help me ? Thanks.

art art
Answer

This is the most silly things I've done. I just forget to import session from library. So should in my public function I put this function.

$this->load->library('session');

This is what happen when you try to built two system simultaneously. Anyway thanks for the response and tried to solve it for me.

Comments