HTML/PHP页面结构以永久重定向到不同的页面


HTML/PHP Page Structing to permanantly redirect to a different page

我正在尝试将此页面结构应用于我的网站的一部分,但我不知道如何使用。这是一个登录用户:

在第1页,用户点击按钮进入第2页

在第2页,用户进行操作以进入第3页

现在,我将成为:

在第1页,用户点击按钮进入第3页

(与中一样,之前最初将他们带到第2页的按钮相同,但由于用户进行了OPERATION,通常将他们引导到2的按钮将他们永久引导到3)

具体来说,我需要帮助的是在OPERATION发生后,让第1页重新缩到第3页,而不是第2页。我该怎么做?我想可能是使用数据库的东西?

这里需要跟踪用户在$_SESSION超全局中的状态。让我解释一下是怎么做的。

当用户进行操作时,会在会话中记录其状态,如下所示:

$_SESSION['operation'] = true;

page1.php

if($_SESSION['operation']){
   // user has already completed the operation
   // redirect the user to page3.php
   header("Location: page3.php");
   exit();
}else{
   // user didn't complete the operation
   // redirect the user to page2.php
   header("Location: page2.php");
   exit();
}

page2.php

// when the user completes the operation, redirect the user to page3.php, like this
header("Location: page3.php");
exit();
  • 设置会话变量以存储operation是否已执行。

  • 按钮链接应根据会话动态设置可变

在操作中()执行以下操作:

opertation()
{
//some stuff here
$_SESSION['op_done']=true;
}

在按钮链接中

<a href="<?php
if(isset($_SESSION['op_done']) && $_SESSION['op_done'])
{
echo "link_to_page3";
}
else 
{
echo "link_to_page2";
}
?>"> Button_Name
</a>

简而言之,创建一个动态按钮链接,该链接将根据会话变量进行调整。