I made an administrative panel using CodeIgniter
and every time the session expires, thus redirecting to the login screen. Every time, for example, that I edit a category, after editing it and clicking another menu link, the system redirects to the login screen again.
config.php (CodeIgniter default file)
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
I do not know if these settings exist, since this "session expiration" is very fast.
The link menu link
user_model.php (login file)
<?php
class User_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function DadosUser()
{
$sessao = $this->session->userdata('user_id');
if (!$sessao AND empty($sessao)) {
redirect(base_url('login'));
}
$this->db->where('id', $sessao);
$user = $this->db->get('admin_users');
if ($user->num_rows() > 0) {
return $user->row();
}
redirect(base_url('login'));
}
}
categories_model.php (model responsible for category)
<?php
class Categorias_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function NovaCategoria()
{
$config['upload_path'] = '../uploads/banners';
$config['encrypt_name'] = true;
$config['allowed_types'] = 'png|gif|bmp|jpg|jpeg|pjpeg';
$categoria = $this->input->post('categoria');
$ordem = $this->input->post('ordem');
$query = $this->db->query("SELECT (MAX(codigo_categoria) + 1) AS codigo FROM Categorias");
$novoCodigo = $query->row()->codigo;
$data = array(
'codigo_categoria' => $novoCodigo,
'nome_categoria' => $categoria,
'ordem' => $ordem
);
if (!empty($_FILES['userfile']['tmp_name'])) {
$this->upload->initialize($config);
if ($this->upload->do_upload()) {
$upload = $this->upload->data();
$data['imagem'] = $upload['file_name'];
}
}
if ($this->db->insert('Categorias', $data)) {
return '<div class="alert alert-success text-center">Categoria cadastrada com sucesso!</div>';
}
return '<div class="alert alert-danger text-center">Erro ao cadastrar categoria.</div>';
}
}