Support » Fixing WordPress » Make page/post password expire after each session. reenter password each visit

  • wpforum

    (@wordpressorgforum)


    I added the following to the child-theme functions.php

    ///time out login so you must reenter it every time//
    add_action( 'wp', 'post_pw_sess_expire' );
        function post_pw_sess_expire() {
        if ( isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
        // Setting a time of 0 in setcookie() forces the cookie to expire with the session
        setcookie('wp-postpass_' . COOKIEHASH, $_COOKIE['wp-postpass_' . COOKIEHASH], time() + 1 * 5, COOKIEPATH);
    }

    I replaced

    setcookie('wp-postpass_' . COOKIEHASH, '', 0, COOKIEPATH);

    with

    setcookie('wp-postpass_' . COOKIEHASH, $_COOKIE['wp-postpass_' . COOKIEHASH], time() + 1 * 5, COOKIEPATH);

    so that you must reenter the password after one minute on the page/per session.

    If I open Chrome, go to the page, I go to http://happynick.com/marketing/extra/private/ and type “private” to enter page.

    When I “Clear Browsing Data” and go back to http://happynick.com/marketing/extra/private/, I am asked to enter “private” each time. Great. But if I go back to the page without closing Chrome, I can still access the page WITHOUT being asked to enter the password.

    In Firefox, I can access it without entering the password again, even after closing Firefox and clearing going to Preferences > Advanced > Cached Web Content > Clear now.

    [please stay with your original topic and add any new information or question there – https://wordpress.org/support/topic/how-to-make-pagepost-password-protected-so-you-must-enter-password-everytime?replies=4 ]

  • The topic ‘Make page/post password expire after each session. reenter password each visit’ is closed to new replies.