View Full Version : PHP To Remember Last Page Visited
11-18-2006, 09:48 PM
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!
11-18-2006, 10:45 PM
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.
11-18-2006, 10:51 PM
Any PHP sites or examples to help? I'm fairly new to this at the mo! Thanks for the reply
11-18-2006, 11:01 PM
An example (bare with me I've not used php for some time so I'm a little rusty :))
$_SESSION['lastpage'] = 'urltopageorsomethinglikethat';
// do your stuff and go to a thank you page
thank you page
// Not getting fancy here:
<meta http-equiv="refresh" content="5; url=<?php echo $_SESSION['lastpage'];?>">
<div>Thank you<br />
<a href="<?php echo $_SESSION['lastpage'];?>">Go back</a>
or something similar to that.
edit: Sorry forgot the go back link, lol. Used a refresh meta instead, but left both for you.
01-10-2007, 02:46 PM
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?
$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 = "firstname.lastname@example.org";
$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!";
<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>
01-10-2007, 08:40 PM
echo "Thank You!";
echo 'Thank You! <a href="$_SERVER[lastpage]">Go back</a>';
01-11-2007, 10:51 AM
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?
01-11-2007, 10:56 AM
Not sure if I understand what you mean...if you want sendmail.php to re-direct to another page...you can use the command...
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 :)
01-11-2007, 02:55 PM
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.
01-11-2007, 02:57 PM
EDIT: Woops nevermind...
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.