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 10 of 10
  1. #1
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts

    PHP To Remember Last Page Visited

    Basically I have a form on my website where users can type in their feedback. When they click send they are taken to a 'Thank You' page. On this thank you page I want to put a link that will take them back to the page they were browsing. As they can get to this page via a few other pages I need it to remember the last page they were on. Also when they return to this page I want all forms cleared if possible.

    I have done this before but can't for the life of me remember how and searching the web has brought nothing, so any help would be most appreciated. Tah!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Sessions.
    Store their last location in a session var, and redirect according to that location. Forms will be cleared automatically if the page is reloaded and no default values are specified for the form.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Any PHP sites or examples to help? I'm fairly new to this at the mo! Thanks for the reply

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    An example (bare with me I've not used php for some time so I'm a little rusty )
    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['lastpage'] = 'urltopageorsomethinglikethat';
    // do your stuff and go to a thank you page
    ?>
    thank you page
    PHP Code:
    <?php
    session_start
    ();

    // Not getting fancy here:
    ?>
    <!DOCTYPE...>
    <html>
        <head>
            <title>Page title</title>
            <meta http-equiv="refresh" content="5; url=<?php echo $_SESSION['lastpage'];?>">
        </head>
    <body>
        <div>Thank you<br />
            <a href="<?php echo $_SESSION['lastpage'];?>">Go back</a>
        </div>
    </body>
    </html>
    or something similar to that.

    edit: Sorry forgot the go back link, lol. Used a refresh meta instead, but left both for you.
    Last edited by Fou-Lu; 11-18-2006 at 10:04 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Right, I've completely forgotten an aspect of this. I've created my form and input it on the page, how do I make it so that when the form is submitted it loads a thank you page?

    The PHP:

    Code:
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    //Save visitor name and entered message into one variable:
    $formcontent="VISITOR NAME: $name\n\nFEEDBACK: $message";
    $recipient = "ahallicks66@hotmail.com";
    $subject = "Contact Form";
    
    $mailheader = "From: $email\r\n";
    $mailheader .= "Reply-To: $email\r\n";
    $mailheader .= "MIME-Version: 1.0\r\n";
    
    mail($recipient, $subject, $formcontent, $mailheader) or die("Failure");
    echo "Thank You!";
    The HTML:
    Code:
    				<form action="sendmail.php" method="POST">
    				<div><b>Your name :</b> <input type="text" name="name"><br>
    				<b>Your e-mail :</b> <input type="text" name="email"><br>
    				<b>Message</b><br /><textarea name="message"></textarea>
    				<input type="submit" value="Send"><input type="reset" value="Clear"></div>
    				</form>
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #6
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    PHP Code:
    echo "Thank You!"
    AS:

    PHP Code:
    echo 'Thank You! <a href="$_SERVER[lastpage]">Go back</a>'

  • #7
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Cool, that's that bit... but how do I get it to read the sendmail.php when the button is clicked but return my thank you page?

    What you have given me is what I need to go on the thank you page, but how do I get it to direct the user to the thank you page once their feedback has been submitted?
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #8
    New Coder
    Join Date
    Jan 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not sure if I understand what you mean...if you want sendmail.php to re-direct to another page...you can use the command...

    header("Location: index.php");

    Replace index.php with thankyou.php or whatever page you want to go to. The header command will only work if you have no sent any output to the screen before it, so it will only help you if sendmail.php simply process the mail, then you can use header to send your user to a thankyou page.

    Im new to php...but I hope that helps

  • #9
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Basically... the user comments on a video they have seen. When they click submit I get an E-Mail telling me what they wrote and their details. At which point I'd like them to go to a page that displays 'Thank You for your feedback' and a link at the bottom to go back to the previous page.
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #10
    New Coder
    Join Date
    Jan 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    EDIT: Woops nevermind...


  •  

    Posting Permissions

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