我正在使用會話在我的網站中將產品存儲在購物車中。但是,當我使用我的購物車中的現有商品登錄後,它會將購物車中添加的最後一件商品的付款加倍。這是因爲當我登錄時,它會再次開始一個會話(重複以前的會話)。我不知道如何解決這個問題。如何避免重複上次會話php session_start();
在cart.php代碼session_start();
if (isset($_GET['add'])) {
$quantity = mysql_query('SELECT id, quantity FROM products WHERE id='.mysql_real_escape_string((int)$_GET['add']));
while ($quantity_row = mysql_fetch_assoc($quantity)) {
if ($quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) {
$_SESSION['cart_'.(int)$_GET['add']]+='1';
}
}
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
`
init.php for login users
`
session_start();
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
$current_file = explode('/', $_SERVER['SCRIPT_NAME']);
$current_file = end($current_file);
if (logged_in() === true) {
$session_user_id= $_SESSION['user_id'];
$user_data = user_data($session_user_id,'user_id','username','password', 'first_name','last_name','email','type','allow_email', 'profile');
if (user_active($user_data['username']) === false) {
session_destroy();
header('Location: index.php');
exit();
}
}
$errors=array();
我想是不是與會話相關的問題,它可能有邏輯錯誤... – user1844933
是的,但我不知道我在哪裏可以找到這個問題 –
可能重複的[如何避免重複上次會話php](http://stackoverflow.com/questions/21124695/how-to-avoid-repeating-last-session-php) – Antony