SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirect Browser Back Button to home page

    I am wondering how can I redirect to the last page(i.e contact_us.php page) with no data input when user click on browser back button.
    so lets say i am on contact_us.php page, when user click in submit on this page it will go to "thankyou.php" page. Now from this page when user click on browser back button i want to redirect to "contact_us.php" page but with no data input (with blank fields). I appreciate if someone can guide me with correct and simple solution.
    thank you

  2. #2
    SitePoint Enthusiast bronze trophy \\.\'s Avatar
    Join Date
    Oct 2013
    Location
    UK
    Posts
    72
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use a session and a flag value that picks up if a value is set then redirect...

    PHP Code:
    <?php
    session_start
    ();
    if( isset( 
    $_SESSION['completed']) ) header("Location: index.php");
    the above would be in your contact form to test if that variable is set

    in your thankyou page you would start a session and set that value so that if someone were to click the back button, the contact page would detect that the session variable has been set and then push the server to serving up the home page.

  3. #3
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the reply, but i solved it with javascript function. Basically now it disable browser back button instead redirecting to any page. and then user can click on the any other page links from Thankyou.php page.

    i have write javascript on contact_us.php form and and called the function on the same page in body tag.

    javascript:
    <SCRIPT type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }
    </SCRIPT>
    <body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">


Bookmarks

Posting Permissions

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