Search code examples
javascriptphphtml.htaccesshttp-redirect

How do I limit access to a page only through redirect from another page


I have two web pages, index.html and home.html. I'm trying to make home.html can only be accessed from index.html so that if a user inputs www.mywbpage.home.html, they'll be redirected to an error page or to index.html..

I linked index.html to home.html with a JS button.

Tried searching all over but the PHP, JS and .htaccess codes I got didn't work...


Solution

  • This can be done without server side, but you know this is a bit sketchy.

    index.html

    var value = "visited";    // or the date of visit!
    localStorage.setItem('my_flag', "visited");
    

    home.html

    var value = localStorage.getItem('my_flag');
    if (value != "visited") {
        window.location = "index.html";
    }
    localStorage.removeItem("my_flag");