Reputation: 3244
I have placed a form on my website, which when submitted redirects the person to a "thankyou page" , but the thing is if someone directly access the "thankyou page", it still shows the stuff i have placed there (Thanks, for submitting the form and all that stuff). I want it to inaccessible when someone directly tried to access it. It should only be displayed when someone has submitted the form (redirected from the form page). Is there a way to allow only the page to be accessible only when redirected from the form page only?
(thankyou page is a php file)
Upvotes: 2
Views: 4073
Reputation: 5890
On the page you where the users submits the form
$_SESSION['submitted_form'] = True;
Then on the thank you page do
if (!isset($_SESSION['submitted_form'])) {
// deny access
} else {
// show real page
}
Upvotes: 1
Reputation: 2348
You can easily check the referrer in thankyou.php page.
<?php
if ($_SERVER['HTTP_REFERER'] == "http://yoursite.com/form.php") {
// continue
} else {
header("Location: http://yoursite.com/form.php");
exit(); //Stop running the script
// go to form page again.
}
?>
Another method is to put an hidden form value in form page, then check the value if it exists. (but users may still look at the code and see hidden value).
Upvotes: 3