wp_get_referer() not working on password protected pages
-
Hello,
Recently it seems like when users are putting in passwords in a password protected page, it just redirects them to /wp-login.php?action=postpass and shows a white screen. I debugged with different plugins/themes and the issue still is there. There are no debug messages/logs that show up either.
I did some debugging and in the wp-login.php file, the wp_get_referer() function does not return the last pages url. This seems to only be the case on some sites/servers as well. When I tried to echo out wp_get_referer() from the wp-login.php file, there was nothing showing up.
I ended up editing the file to use ‘$_SERVER[‘HTTP_REFERER’];’ instead. I know once WordPress updates, this file will be reset back to use wp_get_referer(). Does anyone else have this issue? Anything we can do to make sure the wp_get_referer() works? I have my quick solution for this problem below:
wp-login.php file
case 'postpass': $referer = $_SERVER['HTTP_REFERER']; if ( ! array_key_exists( 'post_password', $_POST ) ) { wp_safe_redirect( $referer ); exit; } require_once ABSPATH . WPINC . '/class-phpass.php'; $hasher = new PasswordHash( 8, true ); /** * Filters the life span of the post password cookie. * * By default, the cookie expires 10 days from creation. To turn this * into a session cookie, return 0. * * @since 3.7.0 * * @param int $expires The expiry time, as passed to setcookie(). */ $expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS ); if ( $referer ) { $secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) ); } else { $secure = false; } setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure ); wp_safe_redirect( $referer ); exit; case 'logout':
– Thanks
- The topic ‘wp_get_referer() not working on password protected pages’ is closed to new replies.