I have been rebuilding my social network in code igniter and am looking for an optimal way to start a session as logged in when the user logs in ( maybe contrary to using code igniters session class? as I want to use their id that is created when they make their account)
I have been able to CREATE a user and hash and salt their password and log them in using the hashed password.
My site is going to have a lot of ‘logged in’ and ‘logged out’ views that vary due to if the user is signed in or not.
That being said, upon login I want to start a logged in session with the id that is created upon sign-up.
Here is my controller that logs the user in minus what I’m trying to do.
function validate_credentials()
{
$this->load->model('user_model', 'um');
$login = $this->input->post('submit');
$this->load->library('encrypt');
if($login) {
$user = $this->um->
validate(array('email' => $this->input->post('email')));
if( $user ) {
if($user->password == $this->encrypt->sha1( $user->salt .
$this->encrypt->sha1($this->input->post('password')))) {
$this->session->set_userdata( array('email' =>
$this->input->post('email')
));
redirect('account/dashboard');
exit;
}
}
}
$this->index();
}
/*---------- EDIT ----------*/
Getting these errors:
Message: Cannot modify header information - headers already sent by (output started at /Users/mycomputer/Sites/cl_ci_new/application/controllers/auth.php:44)
Filename: libraries/Session.php
Line Number: 672
Message: Cannot modify header information - headers already sent by (output started at /Users/mycomputer/Sites/cl_ci_new/application/controllers/auth.php:44)
Filename: helpers/url_helper.php
Line Number: 542
and here are those lines in my code or the Session.php file:
// Set the cookie
setcookie(
this->sess_cookie_name,
$cookie_data,
$expire,
$this->cookie_path,
$this->cookie_domain,
$this->cookie_secure
);
and the url_helpers.php:
switch($method)
{
case 'refresh' : header("Refresh:0;url=".$uri);
break;
default : header("Location: ".$uri, TRUE, $http_response_code);
break;
}
I’m not understanding what the problem is….
On successful validation save a variable in session:
Later on, when needed, check: