Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    how to redirect to home page if not accessed sequentially

    I have three php files, one.php, two.php, three.php
    these three files need to be accessed in sequence. if one.php is submitted it displays two.php. if two.php is submitted, then three.php is displayed. if three.php is submitted then one.php will be displayed. alternately, these three files can be accessed individually. like in the address bar user can type localhost:8080/one.php, localhost:8080/two.php or localhost:8080/three.php. when accessed individually, user should be redirected to one.php because two.php and three.php are getting some values from one.php and error is getting displayed when the later action is performed. How can I achieve this.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Add this as your first set of lines
    Code:
    if($_SERVER['HTTP_REFERER']!="one.php")
      header("Location:one.php")
    Last edited by abduraooft; 09-05-2007 at 08:39 AM. Reason: type error
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    if($_SERVER['HTTP_REFERRER']!="two.php")
    header("Location: one.php")

    I added the above code to three.php because this three.php should come after "two.php". when I tried to access three.php directly it is directing me to one.php which is good. but when I am navigating from one.php then two.php then three.php. here I am expecting that three.php should get displayed. but here also it is redirecting to one.php . Where am I doing the mistake? Thanks in advance for the help.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,147
    Thanks
    2
    Thanked 333 Times in 325 Posts
    $_SERVER['HTTP_REFERER'] is not reliable. Note: The actual name is spelled - 'HTTP_REFERER'. This is spelled incorrectly in the above posts (always turn on full php error reporting when learning, developing, and debugging code. This spelling error would have been pointing out through the use of php error reporting.)

    It depends on which browser is being used, the version, and if the visitor has disabled sending the REFERER in his browser. Also, a script can set it to your page2 value and keep submitting to your page3 code, without actually needing to visit the other pages first...

    I recommend using a session variable to track which page a visitor came from.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    how can I use a session variable. any clue would help me.

    Thanks!

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,147
    Thanks
    2
    Thanked 333 Times in 325 Posts
    Start a session on page1 and unconditionally create a session variable with a value of 1 in it.

    One all the other pages, resume/start a session. If the session does not contain a session variable with the proper value that says the visitor came from the proceeding page, redirect back to page1. Either they got to the current page directly (the session variable won't exit at all) or they got to the current page out of order.

    If the session variable exists with the correct value for the proceeding page, they got to the current page correctly. Set the session variable to the proper value for the current page.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •