I pulled this from my post over at phpacademy and poseted it here as well as I seemingly am getting no hits over there.
So I am following along with the phpacademy - codeigniter video tutorials for creating a user registration & login. I am currently on video 7 which deals with session data.
here is the link to the video => http://www.youtube.com/watch?v=wpUqyTRxbds&feature=BFa&list=EC161C7E0E6A01B1E0
All was going well until I set the session data to display in the members page, at that point my data displayed just as it does in the video minus the email and is_logged_in.
in the video it shows as
Array(
[session_id] =>——————————-
[ip_address]=>—————————
[user_agent]=>——————————-
[last_activity] => —————————-
[user_data] =>
[email] =>————————————-
[is_logged_in] => 1
)
mine has shown as
Array(
[session_id] =>——————————-
[ip_address]=>—————————
[user_agent]=>——————————-
[last_activity] => —————————-
[user_data] =>
)
right then I knew something fishy was going on but I continued anyway with the video doing the restricted.php so now I login (with valid credentials) but still receive the redirect to the restricted page. I can only assume this is because my in my session data my [is_logged_in] is not => 1
I have gone over my code a hundred times and from what I see it matches up with the video tutorial but something obviously is incorrect.
from my main controller
public function members() {
if ($this->session->userdata('is_logged_in')) {
$this->load->view('members');
} else {
redirect('main/restricted');
}
}
public function restricted() {
$this->load->view('restricted');
}
public function login_validation() {
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|callback_validate_credentials');
$this->form_validation->set_rules('password', 'Password', 'required|md5|trim');
if ($this->form_validation->run()){
$data = array(
'email' => $this->input->post('email'),
'is_logged_in' => 1
);
$this->session->set_userdata($data);
redirect('main/members');
} else {
$this->load->view('login');
}
}
from my members page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Members Page</title>
</head>
<body>
<div id="container">
<h1>Members Page</h1>
<?php
echo "<pre>";
print_r($this->session->all_userdata());
echo "</pre>";
?>
</div>
</body>
</html>
As always any help is appreciated (im sure its something obvious but bare with me I ‘m a noob. ) Thanks in advance
