hooks – Session management issues with WordPRess 404 Error page

Question

I have tried to integrate wordpress into my existing website as the documentation archive using the existing login session. I have installed wordpress under /wp of the root app.

In my main app, I set the session: isValidUser = true when the user successfully logs in.

Now, in WordPress, I added the following code in functions.php which seemed to do the trick:

add_action('init', 'validate_session', 1);
function validate_session() {
    if(!session_id()) {
        session_start();
    }

     //Only allow the viewing of doco if logged into application
    if ( !isset($_SESSION['isValidUser']) ) 
    {
        header("Location: http://www.domain.com/");
    }
}

I had some issues with old pages which were cache related but I don’t know how 404’s are handled.

Is the 404 page handled differently? Does it not use the ‘init’ hook when loading?

0
php-b-grader 8 months 2021-12-06T00:49:57-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse