T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/public_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/public_html/TRACK_DUPLICATE_CART_AUDIT.md
# Track Duplicate Cart Addition - Complete Audit

## 🔍 Issue
Clicking "Ajouter au panier" (Add to Cart) twice on track.php causes multiple additions of the same track, but only 1 license should be issued per track.

## 🐛 Root Causes Identified

### Issue #1: Backend Increments Quantity Instead of Preventing Duplicate
**Location:** `cart.php` lines 62-70

**Current Behavior:**
```php
// Check if track already in cart
$found = false;
foreach ($_SESSION['cart'] as &$item) {
    if ($item['track_id'] == $track_id) {
        $item['quantity'] += 1;  // ❌ PROBLEM: Increments quantity
        $found = true;
        break;
    }
}
```

**Problem:** When a track is already in cart, it increments quantity instead of preventing duplicate addition.

**Impact:** 
- User can add same track multiple times
- Multiple licenses would be issued for same track
- Cart shows quantity > 1 for tracks (should always be 1)

### Issue #2: No Frontend Double-Click Prevention
**Location:** `track.php` lines 2750-2786

**Current Behavior:**
- Button is disabled AFTER request starts
- If user clicks twice quickly, both requests can be sent
- No check if request is already in progress

**Problem:** Race condition allows multiple simultaneous requests.

**Impact:**
- Multiple requests sent before first completes
- All requests succeed, adding track multiple times

### Issue #3: No User Feedback for Duplicate Addition
**Location:** `cart.php` lines 62-87

**Current Behavior:**
- Silently increments quantity if track already exists
- No message to user that track is already in cart

**Impact:**
- User doesn't know track was already added
- Confusion about cart contents

## ✅ Expected Behavior

1. **Single License Per Track:** Each track should only appear once in cart with quantity = 1
2. **Prevent Duplicate Addition:** If track already in cart, show message and don't add again
3. **Frontend Protection:** Disable button immediately, prevent multiple clicks
4. **Clear Feedback:** Inform user if track is already in cart

## 🔧 Fixes Required

### Fix #1: Backend - Prevent Duplicate Instead of Incrementing
**Change:** Return error message if track already in cart, don't increment quantity

### Fix #2: Frontend - Immediate Button Disable + Request Flag
**Change:** 
- Disable button immediately on click
- Set processing flag to prevent concurrent requests
- Re-enable only after response

### Fix #3: User Feedback for Duplicates
**Change:** Show clear message: "This track is already in your cart"

## ✅ Fixes Applied

### Fix #1: Backend - Prevent Duplicate Instead of Incrementing ✅
**File:** `cart.php` lines 62-87

**Changes:**
- Removed quantity increment logic
- Now checks if track exists and returns error if found
- Returns `already_in_cart: true` flag for frontend handling
- Message: "This track is already in your cart. Only one license can be purchased per track."

**Result:** Track can only be added once, quantity always stays at 1

### Fix #2: Frontend - Double-Click Prevention ✅
**File:** `track.php` lines 2749-2778

**Changes:**
- Added `addToCartInProgress` flag to track request state
- Button disabled IMMEDIATELY on click (before request)
- Flag prevents concurrent requests
- Flag cleared in `finally()` block

**Result:** Multiple rapid clicks are ignored, only one request sent

### Fix #3: User Feedback for Duplicates ✅
**File:** `track.php` lines 2820-2840

**Changes:**
- Checks for `data.already_in_cart` flag
- Shows warning notification (not error) for duplicates
- Clear message: "This track is already in your cart..."

**Result:** User gets clear feedback when trying to add duplicate

## ✅ Pages Fixed

### Page #1: track.php ✅
- Added `addToCartInProgress` flag
- Prevents double-clicks
- Handles `already_in_cart` response
- Uses actual artist plan from track data

### Page #2: community_fixed.php ✅
- Added `addToCartInProgress` flag
- Prevents double-clicks
- Handles `already_in_cart` response
- Note: Artist plan fetched by cart.php from database

## 📝 Testing Checklist

- [x] Code updated with all fixes on both pages
- [ ] Test rapid double-clicks on track.php (should only add once)
- [ ] Test rapid double-clicks on community_fixed.php (should only add once)
- [ ] Test adding same track twice from track.php (should show warning)
- [ ] Test adding same track twice from community_fixed.php (should show warning)
- [ ] Test with network delays (should prevent concurrent requests)
- [ ] Verify cart shows quantity = 1 for all tracks
- [ ] Verify only 1 license issued per track
- [ ] Test with different tracks (should work normally)


CasperSecurity Mini