Check wp-postpass_* auth cookie (4 posts)

  1. Tom7320
    Posted 3 years ago #

    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!


  2. Tom7320
    Posted 3 years ago #


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


  3. David Choi
    Posted 3 years ago #

    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 ....
  4. wyclef
    Posted 2 years ago #

    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>
    <? } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.