Reputation: 3829
I have a cart on my website on item detail page. The URL of item detail page is http://example.com/location/987/name
where 987 is the ID of restaurant and is treated as r_id
in htaccess rewrite.
Now i want to
r_id
in the URL has been changed.Example:
http://example.com/location/987/name
http://example.com/location/123/name
then all the content in cart shall be cleared.I tried doing as below approach but no luck. Cart is getting cleared even on same URL.
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'] ;
}
Upvotes: 0
Views: 68
Reputation: 3363
I would do it like this:
$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;
}
Upvotes: 1