Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
Call 'wp_logout' when cookie expires (php or javascript)

I am looking for a way to call wp_logout (server side) if my wordpress_logged_in_HASH cookie expires. Unfortunalty I can't find any solution so far. Did a lot of research on stackoverflow and google, but still not done. Does anyone have some advices or ideas how to do it?

Server side I can check if the cookie exits with $_SERVER['HTTP_COOKIE']. The variable exits on my shared server and this works. But how to run wp_logout automaticly when cookie expires? Maybe by some javascript?

if(strpos($_SERVER['HTTP_COOKIE'], 'wordpress_logged_in') == true){
    echo "Login cookie exists!<br>";
    var_dump($_SERVER['HTTP_COOKIE']);
    //echo($startTime = microtime(true));
} else{
    echo "Login cookie not exists!";
    var_dump($_SERVER['HTTP_COOKIE']);
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Simply change session expire time, as mentioned, by adding in your theme's functions.php something like:

add_filter('auth_cookie_expiration', 'my_expiration_filter', 99, 3);
function my_expiration_filter($seconds, $user_id, $remember){

    //if "remember me" is checked;
    if ( $remember ) {
        //WP defaults to 2 weeks;
        $expiration = 14*24*60*60; //UPDATE HERE;
    } else {
        //WP defaults to 48 hrs/2 days;
        $expiration = 2*24*60*60; //UPDATE HERE;
    }

    //http://en.wikipedia.org/wiki/Year_2038_problem
    if ( PHP_INT_MAX - time() < $expiration ) {
        //Fix to a little bit earlier!
        $expiration =  PHP_INT_MAX - time() - 5;
    }

    return $expiration;
}

Surprisingly enough, WordPress does not use PHP sessions at all. It uses only cookies. And it uses a number of them with hashed names.

So don't mess with them directly, and do it the WordPress way with filters like above.

Or by calling WordPress APIs. E.g. if you want to log out the current user, you can call wp_clear_auth_cookie: http://codex.wordpress.org/Function_Reference/wp_clear_auth_cookie

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda