Redirect user by ending php session with Jquery

Asked

Viewed 466 times

0

I’m trying to close a sessão php and redirect a user after password exchange to force new login on the return of an action, the redirect is taking place but I don’t know exactly how to end the session at this time.

What I have in return for the password change is this:

if (response.codigo == "1") {
    $("#msgResultadoSenha").html('×AVISO!' + response.mensagem + '');

    // Atualizando os dados do formulário
    window.location.href = "index.php#ajax/iPerfil.php";

} else {
    $("#msgResultadoSenha").html('×ATENÇÃO! ' + response.mensagem + '');
}
  • 1

    A specific session or all created? session_destroy() eliminates all sessions of that user. $_SESSION['nom_ses'] = '' makes the session receive empty and so "deleted". As you are planning to do?

  • Hello @Everson, as I said in the question, the session I want to end is that of the process that validates the user, as I am planning to do is Jquery + php.

  • 1

    Yes, but for example, you changed the user password in PHP and returned to JS, but could already destroy the sessions after changing the password and then just redirect. Just an idea, if it’s not the way you need it, let’s wait for other users to show you other solutions.

  • Great idea @Everson, was stuck on this issue, already gave me a great direction.

1 answer

0


Following the Everson tip, I did it like this, in php it was like this, after changing the password:

    // DESTRUINDO A SESSÃO
    session_start();
    session_unset();
    session_destroy();
    session_write_close();
    setcookie(session_name(),'',0,'/');
    session_regenerate_id(true);    

On the return:

if (response.codigo == "1") {
    $("#msgResultadoSenha").html('×AVISO!' + response.mensagem + '');

    setTimeout(function(){location.href="login.php"} , 5000);   

} else {
    $("#msgResultadoSenha").html('×ATENÇÃO! ' + response.mensagem + '');
                            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.