![]() 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/.cursor-server/data/User/History/-38ddfbb7/ |
<?php
session_start();
// Set JSON content type
header('Content-Type: application/json');
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
echo json_encode(['success' => false, 'error' => 'User not logged in']);
exit;
}
// Check if it's a POST request
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'error' => 'Invalid request method']);
exit;
}
$data = json_decode(file_get_contents('php://input'), true);
if (!isset($data['index']) || !isset($data['type']) || !isset($data['identifier'])) {
echo json_encode(['success' => false, 'error' => 'Missing required parameters']);
exit;
}
try {
if (!isset($_SESSION['credit_cart'])) {
echo json_encode(['success' => false, 'error' => 'Cart is empty']);
exit;
}
$index = (int)$data['index'];
$type = $data['type'];
$identifier = $data['identifier'];
// Validate index
if ($index < 0 || $index >= count($_SESSION['credit_cart'])) {
echo json_encode(['success' => false, 'error' => 'Invalid item index']);
exit;
}
// Get the item to be removed
$item = $_SESSION['credit_cart'][$index];
// Verify the item matches the expected type and identifier
if ($item['type'] !== $type) {
echo json_encode(['success' => false, 'error' => 'Item type mismatch']);
exit;
}
if ($type === 'track' && $item['track_id'] != $identifier) {
echo json_encode(['success' => false, 'error' => 'Track ID mismatch']);
exit;
}
if ($type === 'credit' && $item['package'] !== $identifier) {
echo json_encode(['success' => false, 'error' => 'Package mismatch']);
exit;
}
// Remove the item
array_splice($_SESSION['credit_cart'], $index, 1);
// Log the action
$itemName = $type === 'track' ? $item['title'] : $item['package'] . ' Package';
error_log("Cart item removed for user ID: " . $_SESSION['user_id'] . " - " . $itemName . " at " . date('Y-m-d H:i:s'));
echo json_encode([
'success' => true,
'message' => 'Item removed successfully',
'removed_item' => $itemName
]);
} catch (Exception $e) {
error_log("Error removing cart item: " . $e->getMessage());
echo json_encode(['success' => false, 'error' => 'Failed to remove item']);
}
?>