<?php
header('Content-Type: application/json');

$website = $_GET['website'];

// Database connection (use your credentials)
$servername = "localhost";
$username = "u111585590_cookies";
$password = "Cookies@076";
$dbname = "u111585590_db_cookies";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die(json_encode(['error' => 'Connection failed: ' . $conn->connect_error]));
}

$sql = "SELECT url, cookies FROM cookies WHERE web = ?";  // Select both url and cookies
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $website);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo json_encode(['url' => $row['url'], 'cookies' => $row['cookies']]); // Return both
} else {
    echo json_encode(['error' => 'No cookies found for this website.']);
}

$conn->close();
?>
