HTML/PHP 页面结构永久重定向到不同的页面
HTML/PHP Page Structing to permanantly redirect to a different page
我正在尝试将此页面结构用于我网站的一部分,但我不知道该怎么做。
这是登录用户:
On page 1, user clicks button to get themselves to page 2
On page 2, user does OPERATION to get themselves to page 3
现在,我会变成:
On page 1, user clicks button to get themselves to page 3
(例如,最初将他们带到第 2 页的同一个按钮,但由于用户进行了操作,通常将他们带到第 2 页的按钮将永久带到第 3 页)
具体来说,我需要帮助的是在 OPERATION 发生后将第 1 页重定向到第 3 页而不是第 2 页。我该怎么做?我假设可能是使用数据库的东西?
设置一个会话变量来存储operation
是否已经被
执行。
按钮的link应该根据session动态设置
变量
在您的 operation() 中执行以下操作:
opertation()
{
//some stuff here
$_SESSION['op_done']=true;
}
在按钮中link
<a href="<?php
if(isset($_SESSION['op_done']) && $_SESSION['op_done'])
{
echo "link_to_page3";
}
else
{
echo "link_to_page2";
}
?>"> Button_Name
</a>
简而言之,制作一个动态按钮 link,它将根据您的会话变量进行调整。
这里您需要在$_SESSION
superglobal 中跟踪用户的状态。让我解释一下如何。
当用户进行操作时,在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();
我正在尝试将此页面结构用于我网站的一部分,但我不知道该怎么做。 这是登录用户:
On page 1, user clicks button to get themselves to page 2
On page 2, user does OPERATION to get themselves to page 3
现在,我会变成:
On page 1, user clicks button to get themselves to page 3
(例如,最初将他们带到第 2 页的同一个按钮,但由于用户进行了操作,通常将他们带到第 2 页的按钮将永久带到第 3 页)
具体来说,我需要帮助的是在 OPERATION 发生后将第 1 页重定向到第 3 页而不是第 2 页。我该怎么做?我假设可能是使用数据库的东西?
设置一个会话变量来存储
operation
是否已经被 执行。按钮的link应该根据session动态设置 变量
在您的 operation() 中执行以下操作:
opertation()
{
//some stuff here
$_SESSION['op_done']=true;
}
在按钮中link
<a href="<?php
if(isset($_SESSION['op_done']) && $_SESSION['op_done'])
{
echo "link_to_page3";
}
else
{
echo "link_to_page2";
}
?>"> Button_Name
</a>
简而言之,制作一个动态按钮 link,它将根据您的会话变量进行调整。
这里您需要在$_SESSION
superglobal 中跟踪用户的状态。让我解释一下如何。
当用户进行操作时,在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();