[英]how to navigate user to correct page?
<?php
$pages = array('Text1.php', 'Text2.php', 'Text3.php', 'Text4.php', 'Text5.php');
// Track $latest in either a session variable
// $current will be dependent upon the page you're on
$latest = $_SESSION['latest'];
$current = basename(__FILE__);
$currentPages = array_search($current, $pages);
$latestPages = array_search($latest, $pages);
if ($currentPages - $latestPages > 1 ) {
?>
<div class="boxed">
<a href="">Continue</a>
<br/>
<a href="Text1.php" id="createLink">Create New</a>
</div>
<?
} else {
// let user do their step
}
?>
我有一个包含五个页面的数组。 现在,此steps.php
已被外部化并存储在一个include()
,该include()
存储在5个php页面中,相同的php页面存储在数组的上方数组中。
现在我想做的是用户应该遵循页面结构。 因此,如果用户在数组中的一个页面上,则他们不能访问另一个页面,除非他们提交了当前所在的页面。
但是我的问题是,如果用户单击“ Continue
链接,我如何获得链接</a>
链接到正确的页面,以便它将用户导航到他们应该正确访问的页面。
如果您的意思是当用户单击“ Continue
”时如何将用户定向到正确的“下一页”,则可以使用currentPages索引+ 1输出下一页
<? if ($currentPages - $latestPages > 1 ) { ?>
<div class="boxed">
<a href="<?= $pages[$currentPages+1] ?>">Continue</a>
<br/>
<a href="Text1.php" id="createLink">Create New</a>
</div>
<? } ?>
据我了解,您正在尝试实现分页吗? 您应该将当前页面,上一页和下一页放在SESSION
变量中,因此在每个请求中,您都可以检查用户是否在SESSION['current']
页面中,然后尝试转到SESSION['previous']
或SESSION['next']
页面,也应该向服务器发送一个“ hiddenfield”值,以便检查用户是否“提交”了该页面(但是,当然,您可以简单地阅读html并找到“ hidden”字段)。 或者,您可以简单地检查提交按钮的“名称”是否在POST(或GET)中? ( if($_POST['NAME_OF_SUBMIT']){}
)-但同样很容易伪造。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.