简体   繁体   English

如何导航用户正确的页面?

[英]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
}

?>

I have an array which contains five pages. 我有一个包含五个页面的数组。 Now this page steps.php is externalized and stored in an an include() which is stored in 5 php pages, the same php pages stored in the array above in the array. 现在,此steps.php已被外部化并存储在一个include() ,该include()存储在5个php页面中,相同的php页面存储在数组的上方数组中。

Now what I am trying to do is the user is suppose to follow the page structure. 现在我想做的是用户应该遵循页面结构。 So if the user is on one of the pages in the array, they cannot access another page until they have submitted the page they are currently on. 因此,如果用户在数组中的一个页面上,则他们不能访问另一个页面,除非他们提交了当前所在的页面。

But my question is that if the user click on the Continue link, how can I get the link </a> to link to the correct page so it navigates the user to the page they should be correctly on. 但是我的问题是,如果用户单击“ Continue链接,我如何获得链接</a>链接到正确的页面,以便它将用户导航到他们应该正确访问的页面。

If you mean how you can direct the user to the correct 'next' page when they click on Continue , you can output the next page using the currentPages index + 1 如果您的意思是当用户单击“ 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>

<? } ?>

As much as I understand, you are trying to implement something like pagination? 据我了解,您正在尝试实现分页吗? You should put current, previous, and next pages in the SESSION variable, so in every request you can check whether the user is in the SESSION['current'] page, and tries to go to the SESSION['previous'] or the SESSION['next'] page, also you should send a 'hiddenfield' value to the server in order to check if the user 'submitted' the page(but of course, one can simply read your html and find the 'hidden' field). 您应该将当前页面,上一页和下一页放在SESSION变量中,因此在每个请求中,您都可以检查用户是否在SESSION['current']页面中,然后尝试转到SESSION['previous']SESSION['next']页面,也应该向服务器发送一个“ hiddenfield”值,以便检查用户是否“提交”了该页面(但是,当然,您可以简单地阅读html并找到“ hidden”字段)。 Or you can simply check whether the submit button's 'name' is in the POST(or GET)? 或者,您可以简单地检查提交按钮的“名称”是否在POST(或GET)中? ( if($_POST['NAME_OF_SUBMIT']){} ) - but again it is simple to falsify, too. if($_POST['NAME_OF_SUBMIT']){} )-但同样很容易伪造。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM