PHP Session数据在页面刷新后丢失


PHP Session data gets lost after page refresh

我正在制作这个产品页面。基本上,它按ID显示产品,并为您提供将其添加到购物车的选项。我的问题是,每次刷新页面时,存储在$_SESSION中的数据都会丢失。

<?php 
    include 'scripts'init.php'; // contains session_start(); and the functions
    if(!IsProductIdSafeAndExisting()) 
    {
        session_write_close();
        header("Location: shop.php");
        die();
    }
    if(isset($_POST['quantity'])) // adds current item to cart but gets lost after refresh
        AddItemToCart($_GET["id"],$_POST['quantity']);
    $id             = $_GET["id"];
    $name           = GetProductField($id,"name");
    $image          = GetProductField($id,"image");
    $price          = GetProductField($id,"price");
    $stock          = GetProductField($id,"stock");
    $details        = GetProductField($id,"details");
    $total_products = GetTotalProducts();
    $total_price    = GetTotalProductsPrice();
    LoadHeaderByTitle($name." | Magazin Vinuri");
 ?>
<body>
    <div id="page">
        <?php LoadNavigationBy(""); ?>
        <div id="body">
            <div class="header">
                <div>
                    <h1><?php echo $name; ?></h1>
                </div>
            </div>
            <div class="singlepost">
                <div class="featured">
                    <img src="images/<?php echo $image; ?>" alt="">
                    <h1><?php echo $name.' - '.$price.' lei'; ?></h1>
                    <span>Mai sunt <?php echo '<strong>'.$stock.'</strong>'; ?> bucati ramase.</span>
                    <p><?php echo $details; ?></p>
                    <div class="additem">
                    <center>
                        <form method="POST" action="product.php?id=<?php echo $id; ?>">
                            <input type="text" name="quantity" value="Cantitate" onblur="this.value=!this.value?'Cantitate':this.value;" onfocus="this.select()" onclick="this.value='';">
                            <input type="submit" value="Adauga" id="submit">
                        </form>
                        </center>
                    </div>
                </div>
                <div class="sidebar">
                    <h1>Cosul tau</h1>
                    <img src="images/cart.png" alt="">
                    <h2><?php echo $total_price; ?> lei</h2><br>
                    <p>Momentan aveti <strong><?php echo $total_products; ?></strong> produse in cos. Pentru a edita lista de produse dati click pe butonul de mai jos.</p>
                    <a href="cart.php" class="more">vezi cumparaturi</a>
                </div>
            </div>
        </div>
<?php include 'scripts'overall'foot.php' ?>

init.php

<?php
    session_start();
    require 'database'connect.php';
    require 'functions'general.php';
    require 'functions'engine.php';
?>

问题是我像这样存储产品id $_SESSION[10]=什么;这是错误的,因为它与$_SESSION['10']=某事相同;所以我把它改成$_SESSION['id_10']=something;现在可以运行了