【发布时间】:2014-12-30 18:42:31
【问题描述】:
我有一个存储 2 个数组的会话,$_SESSION["info"] 和 $_SESSION["cart"] 现在当用户注销时,信息会话被破坏所以 unset($_SESSION["info"] 但是购物车会话仍然存在。信息会话存储用户的 ID,现在我试图从信息数组中检索该用户的 ID,并在用户注销时将其存储在 cookie 中,因此当用户重新登录时,如果用户 ID存储在会话中的 cookie 用户 ID 匹配它使用与该用户 ID 相关的购物车数组。
这是我目前所拥有的,在我的 logout.php 中:
$_COOKIE["userID"] = $_SESSION["info"]["id"];
unset($_SESSION["info"]);
在我的wishlist.phtml中:
<?php
if (isset($_SESSION["cart"])) {
if (count($_SESSION["cart"])>0) {
echo '<br><br>';
echo '<table class="table table-hover"><thead><tr>';
echo '<th>Owner</th><th>Car</th><th>Price</th><th class="text-center">Action</th> </tr>';
echo '</thead><tbody>';
foreach ($_SESSION["cart"] as $key => $wish) {
echo '<tr><td>' . $wish["username"]. '</td><td>' . $wish["car"]. '</td><td>' .$wish["price"]. '</td><td class="text-center"><a href="/removecar.php?car='.$key. '"><button id="view" type="button" class="btn btn-danger">x</button></a></td></tr>';
}
echo '</tbody></table>';
}
else {
echo '<div class="alert alert-danger">You do not have any cars in your wishlist.</div>';
};
}
?>
有人知道我应该怎么做吗?
【问题讨论】: