Limit Direct Access .. ?

Discussion in 'PHP' started by gasper000, Aug 1, 2009.

  1. #1
    I have made a form that whenever the user completes the registration successfully, it redirects him/her to a new page (thankyou.php) saying "thank you for registering, bla bla....". It works fine but I want to prevent the direct access to thankyou.php so if the user types "www.mysite.com/thabkyou.php/" it redirects him to the form without displaying the thank you message. But in case the user succeeds to register, thankyou.php opens & displays the thank you message.

    Do you have any idea how can I do that ?
     
    gasper000, Aug 1, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Set a cookie or a session variable on the form page. Check for the value on the thankyou page.

    //Form.php
    session_start();
    $_SESSION['some_variable'] = true;

    //Thankyou.php
    If (!$_SESSION['some_variable']){ header("Location: goback.php")};
     
    jestep, Aug 1, 2009 IP
    gasper000 likes this.
  3. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    SOLVED..!
    Thank you very much. I had to add session_start(); at the beginning of thankyou.php. Very helpful.
     
    gasper000, Aug 2, 2009 IP