I have a question about setting token for cookies.
When the user checks the remember me it will insert the user id and identifier and token to my auto login table
But the token should that be stored in a session?
I can set the cookie data fine but now it just trying to make the checks work so when user has clicked remember me it will auto log them in.
I am just new to creating a remember me with id and tokens.
http://pastebin.com/JmRk6d3M
When the user checks the remember me it will insert the user id and identifier and token to my auto login table
But the token should that be stored in a session?
I can set the cookie data fine but now it just trying to make the checks work so when user has clicked remember me it will auto log them in.
I am just new to creating a remember me with id and tokens.
http://pastebin.com/JmRk6d3M
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->library('encryption');
$this->load->helper('url');
$user_id = '1';
$identifier = crypt($user_id,'$6$5,j$2.$');
$token = "$2y$10$".bin2hex(openssl_random_pseudo_bytes(22));
$timeout = time() + 60 * 60 * 24 * 7;
$remember = $this->input->post('remember');
if (isset($remember)) {
$data = array(
'user_id' => $user_id,
'token' => $token,
);
//$this->session->set_userdata($data);
/*
If the user checks the remember me checkbox then insert
the identifier and token to database
*/
$cookie = array(
'name' => 'remember',
'value' => "$identifier:$token",
'expire' => $timeout,
'domain' => '.localhost',
'prefix' => '',
'secure' => FALSE
'httponly' => TRUE,
);
$this->input->set_cookie($cookie);
}
$this->load->view('welcome_message');
}
}