I’m trying to make my first login without just downloading a file and implementing it in my site.
So I made a member model (model_member) and a controller (account). In the view file im checking if the user is logged in and if they’ve made a character or not and to display different things based on the results of that.
But its saying I am logged in even though im not. Or my session is messing up and when i close the browser its staying logged in. (haha)
Here is my code:
Model:
class model_member extends CI_Model {
public function save ($data) {
$this->db->insert('member', $data);
$this->session->set_userdata('email', $data['email']);
$this->session->set_userdata('password', $data['password']);
}
public function isLoggedIn () {
if ($this->session->userdata('email')) {
return true;
} else if ($this->session->userdata('email')) {
return false;
}
}
}
Controller:
public function register () {
//Load model
$this->load->model('model_member');
//If post send pass and email to model
if ($this->input->post()) {
$data['email'] = $this->input->post('email');
$data['password'] = md5($this->input->post('password'));
$this->model_member->save($data);
}
//Set title
$data['title'] = 'Register';
//Load view
$this->template->write_view('content', 'account/register', $data);
$this->template->render();
}
And just for the sake of it, my view: (using a codeigniter template)
<div id ="game-home">
<div id="intro">
<? if ($loggedIn == true && $charMade == false) { ?>
<a href="#">Make a Character</a>
<? } else if ($loggedIn == False && $charMade == false) { ?>
<a href="#">Make an Account</a>
<? } else if ($loggedIn == true && $charMade == true) { ?>
Game Coming Soon!
<? } ?>
</div>
It’s saying make a character not matter what. I’ve looked over it for a while and im hoping it isnt just something stupid. Thanks in advance for the help.
Answer ———-
“Have you tried this in another browser? Just to make sure, that is not a session problem. Btw, for testing purpose you should use this: $this->session->sess_destroy(); somewhere. If the CodeIgniter’s own session uses cookie to store session data, it can cause your problem even after a browser restart.” – Gergely Bacso