會話存儲陣列似乎只記住一個鍵值對。當我在瀏覽器中按下後退按鈕時,數組似乎是空的。我究竟做錯了什麼? 下面的代碼: 感謝您的幫助
<?php
if(!isset($_SESSION)) {
session_start();
$_SESSION['cart']=array();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
\t <meta charset="UTF-8">
\t <title>Shoppy</title>
</head>
<body>
<div><a href="index.php">back to store</a></div>
\t \t \t <?php include 'products.inc.php'; ?>
\t \t \t <?php $p=$_GET["product"] ?>
\t \t \t <span><?php echo $products[$p]['name']; ?> </span><?php echo $products[$p]['price']; ?> €
\t \t \t <div>
\t \t \t \t <img src="<?php echo $products[$p]['picture']; ?>" alt="">
\t \t \t </div>
\t \t \t
\t
\t
\t <form action="" method="POST">
\t \t <input type="hidden" name="form" value=<?php echo $p ?>>
\t \t <button type="submit">buy</button>
\t </form>
\t <?php if (!empty ($_POST) && isset($_POST))
{
\t array_push($_SESSION['cart'], $_POST['form']);
\t
\t } ?>
\t <?php include 'cart.inc.php'; ?>
</body>
</html>
也許是因爲你清除車在每一頁上的負載?(4號線) – Halcyon 2015-02-24 00:15:47