WordPress.org

Support

Support » Plugins and Hacks » Hacks » Check wp-postpass_* auth cookie

Check wp-postpass_* auth cookie

  • Hi there!

    I have a WP site with a couple of password protected pages. After a user has entered the corrrect password WP creates a cookie called wp-postpass_*. I want to check wether or not the user logged in to a specific page correctly within my own PHP script. I found the wp_authenticate_cookie() function but I still don’t understand how to use this function within my own script to check for different password protected pages… 🙁

    Help would be very much appreciated!

    THX a lot!

    Tom

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi!

    Sorry, but I’d like to push this issue since unfortunately I don’t have a solution yet…

    THX!!!

    David Choi
    Member

    @wpthemes777

    The idea will be

    if(!empty($post->post_password) &&
       $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password))
    {
       .... password protected, blocks user ....
    }
    elseif (isset($_COOKIE['wp-postpass_' . COOKIEHASH])
     && $_COOKIE['wp-postpass_' . COOKIEHASH] == $post->post_password){
        .... password matches, allow access ....
    }

    Hello, I’m wondering if there was ever any resolution on this?

    I have a similar situation that was working fine pre WP 3.4.2. This following no longer seems to work.

    $urlSplits = explode('/', $_SERVER['REQUEST_URI']);
      if (isset( $_COOKIE['wp-postpass_' . COOKIEHASH]) && $urlSplits[3] == 'logout') {
        $pastdate = mktime(0,0,0,1,1,1970);
        setcookie('wp-postpass_' . COOKIEHASH, '', $pastdate, COOKIEPATH );
        header('Location: http://www.myurl.com/my-section/password-protected');
      } 
    
    <?
    $sql = "SELECT post_password FROM wp_posts WHERE ID = '173'";
    $result = mysql_query($sql) or die('Content was not loaded. Please refresh your page.');
    while($post = mysql_fetch_array($result)) {$pagePass = $post['post_password'];}
    ?>
    
    <? if (isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) && $pagePass == $_COOKIE['wp-postpass_' . COOKIEHASH]) { ?>
      <a href="<? echo site_url('/my-section/password-protected/logout'); ?>" class="open">Member Logout</a>
    <? } else { ?>
    
      <a href="<? echo site_url('/my-section/password-protected/'); ?>" class="close">Member Area</a>
    <? } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Check wp-postpass_* auth cookie’ is closed to new replies.