Preventing direct access to a page

Discussion in 'PHP' started by Mr.Bill, Oct 12, 2007.

  1. #1
    How would I be able to research this or do this. I have made a splash page that has some text and ads then a link to another page. So I have mydomain.com with a link to mydomain.com/otherpage.html Now if you type in the address mydomain.com/otherpage.html it will take you straight to that page. I do not what this I want them to be redirected to mydomain.com if they try to reach the page directly. The only way to access mydomain.com/otherpage.html is by first visiting mydomain.com and clicking the link.

    Is this possible without having a signin type site? Maybe using something like a check box that would say I agree to the terms and conditions and then mydomain.com/otherpage.html would verify that they have checked the box.
     
    Mr.Bill, Oct 12, 2007 IP
  2. xxclixxx

    xxclixxx Peon

    Messages:
    28
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well first you'd need to either run html pages as PHP to do it, or link to a PHP page. After that, you could use $HTTP_REFERER to see if the referring page is the main page.
     
    xxclixxx, Oct 12, 2007 IP
  3. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This can be done on PHP ofcourse :)

    On start page at the first lines you must put following PHP code

    
    session_start();
    $_SESSION['wasOnFirstPage'] = true;
    
    PHP:
    on second page following code
    
    session_start();
    if (!$_SESSION['wasOnFirstPage']) 
     header('Location: /');
    
    PHP:
    so after this code user will be redirected to mydomain.com if he visit second page without visiting first page.
     
    Squash, Oct 12, 2007 IP