我的网站上有项目详情页面上的购物车。商品详细信息页面的网址为http://example.com/location/987/name
,其中987是餐馆的ID,在htaccess重写中被视为r_id
。
现在我想
r_id
已更改,请清除购物车。示例:
http://example.com/location/987/name
http://example.com/location/123/name
,则应清除购物车中的所有内容。我尝试按照以下方法做但没有运气。即使在相同的网址上,购物车也会被清除。
if(empty($_SESSION['re_in_ss']) && isset($_GET['r_id'])) {
$_SESSION['re_in_ss'] = $_GET['r_id'];
}
else if($_SESSION['re_in_ss'] != $_GET['r_id']){
$cart->empty_cart();
$_SESSION['re_in_ss'] = $_GET['r_id'] ;
}
答案 0 :(得分:1)
我会这样做:
$rid = isset($_GET['r_id']) ? $_GET['r_id'] : null;
if(empty($rid)) die('r_id is missing');
if(!isset($_SESSION['re_in_ss']) || $_SESSION['re_in_ss'] != $rid) {
$cart->empty_cart();
$_SESSION['re_in_ss'] = $rid;
}