希望有人能幫我解決這個問題..我有一個表格來爲用戶選擇需要的類別。我使用此表單的複選框讓他們選擇類別。當他們選擇類別時,我在SESSION上保存所選的類別,並在該類別頁面之後重定向到下一頁。防止瀏覽器錯誤再次轉到上一頁
這個過程是這樣的......
if ($totalCategory >= 1 && $totalCategory <= 10) {
$_SESSION['category'] = $_POST['category'];
$url = BASE_URI . 'select_subject.php'; // Define the URL:
header("Location: $url");
exit(); // Quit the script.
}
我的問題是,當頁面重定向到下一個頁面(select_subject.php)有時候用戶可能需要返回到分類頁面再次使用後退按鈕在瀏覽器上更改他們選擇的類別。但是當它發生時,它不會再次進入類別頁面,瀏覽器顯示類似這樣的錯誤...
文檔已過期,該文檔已不再可用。
注意:但是當我點擊頁面重新載入按鈕頁面顯示正常。
在這種情況下,我需要從別人幫助從這避免和我需要用正確顯示先前選定的類別再次顯示類別頁面..
UPDETE CODE:
<?php
if (isset($_GET['submitted_category'])) {
if (isset ($_GET['category']) && is_array($_GET['category'])) {
$_SESSION['selectedcatcount'] = count($_GET['category']);
$totalCategory = count($_GET['category']);
if ($totalCategory >= 1 && $totalCategory <= 10) {
$_SESSION['category'] = $_GET['category'];
$url = BASE_URI . 'select_subject.php'; // Define the URL:
header("Location: $url");
exit(); // Quit the script.
} else {
echo '<div class="error">
<img src="images/error.png" />
<p style="margin:2px 0 0;">Please select atleast 1, not more than 10 categories.</p>
</div>'; }
} else {
echo '<div class="error">
<img src="images/error.png" />
<p style="margin:2px 0 0;">This can not be empty. Please select atleast one category.</p>
</div>';
}
}
$q = 'SELECT * FROM category ORDER BY category_id';
$r = mysqli_query($dbc, $q);
$c = 0;
$i = 0;
echo '<form action="" method="get" accept-charset="utf-8">';
echo '<table><tr>';
while($row = mysqli_fetch_array($r, MYSQLI_ASSOC )){
// if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row:
if(($c % 2) == 0 && $c != 0){
echo "</tr><tr>";
}
echo '<td width="50%">
<input type="checkbox" name="category[]" value="' . $row['category_id'] . '" />' . $row['category_name'] .
'</td>';
$c++;
} // while..
// in case you need to fill a last empty cell:
if (($i % 2) != 0){
// str_repeat() will be handy when you want more than 2 columns
echo str_repeat("<td> </td>", (2 - ($i % 2)));
}
echo "</tr></table>";
?>
</div>
<div class="continue">
<p>Please click 'Continue' button to proceed to next step</p>
<input type="submit" value="Continue" class="continue-btn" />
<input type="hidden" name="submitted_category" value="TRUE" />
</div>
</form>
希望有人幫助我.. 謝謝..
任何人都可以幫助我解決這個問題..謝謝。 – TNK
可能解決[這裏](http://stackoverflow.com/questions/660329/prevent-back-button-from-showing-post-confirmation-alert) – Niloct