簡體   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
}

?>

我有一個包含五個頁面的數組。 現在,此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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM