阻止访问感谢页面?

时间:2013-08-10 17:43:01

标签: php get conditional-statements

我有一个php表单,我正在重定向:

http://wthdesign.net/contact.php

到这个网址:

http://wthdesign.net/contact.php?status=thanks

我的表单发送完毕后:

但我的问题是,如果首先从未发送表单,我该如何阻止访问此网址?

2 个答案:

答案 0 :(得分:2)

你只需要在表单中创建会话,你需要检查会话是否使用isset函数设置。如果没有,请在开始时使用die。

if (!isset($_SESSION['thank'])) die;

答案 1 :(得分:1)

向我们展示contact.php的源代码

确实,SESSION是最好的方式,并设置这样的会话。

if (mail(...)) {
  $_SESSION['allow_show_thanks'] = 1;
}

您是否有某种处理状态的开关案例?

if (status == "thanks") {


} else {
  // show form
}

将其更改为

if (status == "thanks" && (isset($_SESSION['allow_show_thanks'] && $_SESSION['allow_show_thanks'] == 1) ) {
   // show thanks when status equals "thanks" AND SESSION['allow_show_thanks'] == 1

} else {
  // show form
}
相关问题