One Hat Cyber Team
Your IP :
216.73.216.186
Server IP :
88.222.243.193
Server :
Linux in-mum-web1837.main-hosting.eu 5.14.0-503.34.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 27 06:00:50 EDT 2025 x86_64
Server Software :
LiteSpeed
PHP Version :
8.2.28
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
u322583024
/
domains
/
awaha.in
/
public_html
/
View File Name :
display_wishlist.php
<?php session_name('vaishnavi_awaha'); session_start(); header('Content-Type: application/json'); include 'admin/connection.inc.php'; if (!$conn) { die(json_encode(['success' => false, 'message' => 'Database connection failed'])); } $input = file_get_contents("php://input"); $data = json_decode($input, true); $product_id = $data['product_id'] ?? null; if (!$product_id) { die(json_encode(['success' => false, 'message' => 'Product ID is missing'])); } if (isset($_SESSION['user_id'])) { $user_id = $_SESSION['user_id']; // Check if the product is already in the wishlist $checkStmt = $conn->prepare(" SELECT id FROM wishlist WHERE user_id = ? AND product_id = ? "); $checkStmt->bind_param('ii', $user_id, $product_id); $checkStmt->execute(); $result = $checkStmt->get_result(); $existingWishlistItem = $result->fetch_assoc(); $checkStmt->close(); if ($existingWishlistItem) { echo json_encode(['success' => false, 'message' => 'Item is already in the wishlist']); } else { // Insert into wishlist $insertStmt = $conn->prepare(" INSERT INTO wishlist (user_id, product_id, added_on) VALUES (?, ?, NOW()) "); $insertStmt->bind_param('ii', $user_id, $product_id); if ($insertStmt->execute()) { echo json_encode(['success' => true, 'message' => 'Item added to wishlist']); } else { echo json_encode(['success' => false, 'message' => $insertStmt->error]); } $insertStmt->close(); } } else { // Save to cookies/localStorage for guests $wishlist = isset($_COOKIE['wishlist']) ? json_decode($_COOKIE['wishlist'], true) : []; if (isset($wishlist[$product_id])) { echo json_encode(['success' => false, 'message' => 'Item is already in the wishlist (guest)']); } else { $wishlist[$product_id] = true; setcookie('wishlist', json_encode($wishlist), time() + (86400 * 7), '/'); echo json_encode(['success' => true, 'message' => 'Item added to wishlist (guest)']); } } $conn->close(); ?>