Visiting Webpage ONLY after another page was visited. Possible?

I am looking for a way to solve the following problem:

User should only be able to visit mywebsite.com/page2/ after they visited mywebsite.com/page1/

Read More

If a user was not on page1, s/he should not be able to visit page2.

Is this possible?

Further specification: On page1 should be a survey (plugin: “Contact Form 7”) and people are redirected to page2 after submitting their answers.

Related posts

Leave a Reply

1 comment

  1. You could set a cookie upon contact form submission, then check for the cookie on /page2. If it is not found, wp_safe_redirect() back to /page1.

    Setting a cookie – You will need to hook into Contact Form 7’s submission – look into their documentation:

    <?php
    setcookie( 'my_cookies_name', true, 0 ); // This cookie will expire after the session
    ?>
    

    Retreiving the cookie (on /page2‘s php template:

    <?php
    if( is_page('page2') ) {
        // Because the value is set to true, you can just check for the value in if()
        if( ! $_COOKIE['my_cookies_name'] ) {
            // cookie isn't found, redirect back
            wp_safe_redirect( site_url('/page1') );
        }
    }
    ?>