WordPress.org

Ready to get started?Download WordPress

Forums

WP Login redirecting to previously visited page (3 posts)

  1. drew4663
    Member
    Posted 1 year ago #

    I have a WP install on a single domain and some custom PHP pages not part of WP but in the root folder. When the pages are accessed directly I want it to check if the user is logged in or not, which I currently have

    <?php
    require('../wp-load.php');
    get_header();
    if ( is_user_logged_in() ) {
       echo "Welcome, Registered User";
    } else {
    	header("Location:../wp-login.php?location=" . urlencode($_SERVER['REQUEST_URI']));
    	exit;
    }
    ?>

    This function is on the page I want protected and it works. What it does is checks if the end user viewing the page is logged in. If the end user is logged in the text, "Welcome, Registered User", is shown and then the page contents. If not authenticated, the page redirects to the login page and the url displays "http://www.mydomain.com/wp-login?location=%2Fsubfolder%2Fmypage.php"

    How can I get that url to redirect after successful login to http://www.mydomain.com/subfolder/mypage.php

    ??????ANY THOUGHTS????

  2. drew4663
    Member
    Posted 1 year ago #

    Hello????

  3. drew4663
    Member
    Posted 1 year ago #

    I found out the answer. All you need to do is place the following code into the non-wordpress page you would like to check for authentication and after login it will redirect you to the page you were previously on.

    <?php
    require('../wp-load.php');
    get_header();
    php auth_redirect();
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic