简体   繁体   English

仅在从特定页面重定向时才允许访问?

[英]Allow access only when redirected from a particular page?

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). 我已经在我的网站上放置了一个表单,在提交时将该表重定向到“ thankyou页面 ”,但问题是如果有人直接访问“thankyou页面”,它仍会显示我放在那里的东西(谢谢,提交形式和所有东西)。 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) (thankyou页面是一个php文件)

You can easily check the referrer in thankyou.php page. 您可以在thankyou.php页面中轻松查看引荐来源。

<?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). (但用户仍然可以查看代码并查看隐藏值)。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM