• Hello All,

    I use a WP blog inside a website I built from scratch. The website has to be entered through the index page which starts a session in PHP. This is done for security reasons, ensuring any attempt to access another page redirects the user to the index page. That all works fine.

    However, the blog can be accessed by sidestepping the index page. When I tried implementing sessions in the blog to prevent direct access to it, the whole blog bombed.

    The path to the blog: http://www.website.com/blog/

    I want to use the same session variable controlling the rest of my website to restrict access to the blog to where all users have to first go through the index page.

    Any help would be greatly appreciated!

    Thanks in advance.

    Sincerely,

    wordman

Viewing 1 replies (of 1 total)
  • You can set up a new function in your theme’s functions.php file, or in a plugin that you create. Get that function to check for the session variable that you want and link it to the systems using add_action().

    As an example…

    function check_session () {
        if (!array_key_exists ($_SESSION, "myvalue")) {
            header ("Location: http://www.mysite.com");
            die ();
        }
    }
    
    add_action ("init", "check_session");

    Please note that there was no testing done, and there’s no guarantee that will work, but it’s a starting point for you.

Viewing 1 replies (of 1 total)
  • The topic ‘Restricting access to WP blog using sessions’ is closed to new replies.