[eluser]blitzneo[/eluser]
I'd like to 'reactivate' this thread, since I am coding a similar website that will implement the "Remember me" functionality.
As for my previous example I also created a MY_Controller file to check if a user is logged in or not, which is working.
Now, if a user checks the Remember me checkbox, I create a cookie, this way:
Code:
if(isset($_POST['remember']))
{
// create cookie
$public_key = md5('test');
$remember_cookie = array(
'name' => 'test',
'value' => $public_key,
'expire' => '1209600',
'path' => '/'
);
set_cookie($remember_cookie);
Now I have several questions..
1.- Shall I update or insert a row in the ci_sessions table with the information the user entered ? If so, how to ?
Code:
$insert = array(
'user_id' => $this->session->userdata('id'),
'public_key' => $public_key,
'private_key' => md5('private'),
'ip_address' => ip2long($_SERVER['REMOTE_ADDR'])
);
$query = $this->db->insert('ci_sessions', $insert);
By doing that, I miss several ci_sessions table rows.. :S This is the table, shall I extend the sessions library or ?
Code:
CREATE TABLE `ci_sessions` (
`session_id` varchar(40) NOT NULL,
`user_id` bigint(20) unsigned NOT NULL,
`public_key` varchar(32) NOT NULL,
`private_key` varchar(32) NOT NULL,
`ip_address` varchar(16) NOT NULL,
`user_agent` varchar(50) NOT NULL,
`last_activity` int(10) NOT NULL,
`user_data` text NOT NULL,
PRIMARY KEY (`session_id`),
KEY `user_id` (`user_id`,`public_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
2.- Once I manage to fill up that info, how to check for that cookie and its values ? Should be prior or after checking if a user is logged in ?
Code:
class Main_controller extends CI_Controller {
public $data = array();
public function __construct()
{
parent::__construct();
if ($this->session->userdata('logged_in') === TRUE)
{
// ...
}
else
{
// check cookie
get_cookie('test');
// ...
redirect('login');
}
}
}
3.- After checking that info, I should update that cookie with new data, and update the ci_sessions table with same data as well, right ?
Thanks.