1
I have the following problem: when trying to accomplish the logon in some browsers or even on mobile phone (it does not occur at all, my friend for example can log in normally), the session simply is not started and the person remains unattended.
No error code return. I have changed the session settings for CodeIgniter
to save to database, save to folder, and nothing solves.
I would like the help of CodeIgniter
, because I have tested several things. I leave here some of my settings, to help:
config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
After typing the form
Send what he typed in the 2 fields and send to the controller, in the controller I get them like this:
$user = $this->input->post('user');
$senha = md5($this->input->post('senha'));
And send to model Login
$result = $this->login->entrar($user, $senha);
In the model:
public function entrar($user, $senha){
return $this->db->query('select *
from usuario
where (usuario = ? or email = ?)
and senha = ?',array($user, $user, $senha))->row();
}
If the return variable is not empty (get output with select) I save the session that is already started in Codeigniter autoload
$autoload['libraries'] = array('session', 'database');
How I record the session: ($result
is the variable that comes back with user data)
$this->session->set_userdata('id', $result->id);
$this->session->set_userdata('nome_completo', $result->nome_completo);
$this->session->set_userdata('email', $result->email);
$this->session->set_userdata('usuario', $result->usuario);
$this->session->set_userdata('senha', $result->senha);
After that When I give the following command after saving the session
print_r($this->session->userdata());
I get the session saved correctly, but after reloading the page to refresh the user data on the screen the session is not set, and the print_r result is
array{}
OBS: Before my website was at the following address: http://meulivro-teste.000webhostapp.com, now I bought a package of accommodation at Hostinger, and it is on the site: http://www.conteumahistoria.com.
Additional The PHP version was in 7.3 on Hostinger, I went back to 7.1 to see if it fixed, but nothing changed
It is not possible to know if you are loading the library in the correct way. It is not possible to know in which way the method is recovering the data. It is not possible to know which variables you use to validate the session. You can’t know how the session is validated in the browser (since you report that in some, it works). Show the code. Show minimally how to record, retrieve and validate the session.
– ShutUpMagda
I will edit and complement with the data you spoke
– VitorZF
You have already tried to load librarie Session in the autoload.php configuration file?
– Phelipe
She’s pressing the autoload, like I showed you up there
– VitorZF
Basically vc confirms if user and password informed exist in the database, and if true, retrieves the user data from the database and writes them in the session. But what’s the Function/method validating the data recorded in the session? This is the problem. It is not enough to write a session with the user data, the
php
(or the browser) has to know what these data are for, if they are still valid or if they are exploited, etc.– ShutUpMagda
I use the $this->Session->has_userdata('usenomequesalvei') method that is the default for codeigniter, if there is something saved as in the session’s'usenomequesalvei' field it returns true
– VitorZF
Possible duplicate of PHP Controller with Codeigniter
– ShutUpMagda
This method does not serve for this, and is already obsolete in the new version of
CodeIgniter
. Thehas_userdata($key)
will only confirm that a session item exists, but does not control authentication. I believe your question is a duplicate of this one: https://answall.com/questions/180083/controle-de-sessions-php-com-codeigniter. That’s exactly what you’re looking for...– ShutUpMagda
But the problem is not in validating the session, but rather that the session is not set, soon after logging in I give print_r throughout the session and the session appears, but when resetting the page and give print_r($this->Session->userdata()) there is nothing else in the session
– VitorZF