我有四页:cart.php、checkout1.php、checkout2.php和checkout3.php。他们的职能摘要如下:
cart.php //display items and quantities in cart with option for coupon code
checkout1.php //input of user address
checkout2.php //order summary
checkout3.php //order placed into SQL东西是通过$_SESSION保存在购物车中的,但是在每一页之间,我使用$_POST将信息从一个带到下一个页面。例如,当用户从地址栏转到www.site.com/checkout2.php时,我担心的是它将显示一个空页面(但仍然允许他们继续使用checkout3.php并浪费SQL空间)。在每个页面上,如果购物车是空的,我就重定向到index.php (例如。在空手推车上输入地址栏,它不会显示允许您继续的代码),但是如果checkout2.php中有内容而没有$_POST,我不知道如何防止用户搞砸。
我想可能使用类似于isset()的东西,但我想要类似于(伪代码)的东西:
//on checkout2.php
if (previouspage != "./checkout1.php") {
echo "There was an error.";
} else {
//display correct page
}我知道有$_SERVER['HTTP-REFERER']或类似的东西,但我的理解是,并不是每个浏览器都支持这一点,而且它也没有给出引用页面的简洁位置(例如。会说用户来自www.site.com和www.site.com/checkout1.php)
发布于 2013-10-05 20:26:49
您可以使用以下简单的方法:
1-创建名为steps的会话变量
2-一旦用户从一个步骤移动到另一个步骤,将变量增加1。
3-在每一页的顶部,检查steps变量是否对该页有效
例如,:
Cart.php
$_SESSION['steps'] = 1;checkout.php
if(isset($_SESSION["steps"]) && $_SESSION["steps"] == 1){
//die or redirect
}
//once all the logic execute properly
$_SESSION['steps'] = 2;checkout2.php
if(isset($_SESSION["steps"]) && $_SESSION["steps"] == 2){
//die or redirect
}
//once all the logic execute properly
$_SESSION['steps'] = 3;checkout3.php
if(isset($_SESSION["steps"]) && $_SESSION["steps"] == 3){
//die or redirect
}
//once all the logic execute properly
unset($_SESSION['steps']);https://stackoverflow.com/questions/19202209
复制相似问题