
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
header("Content-Type: application/json");

// Database connection details
$host = "localhost";
$dbname = "balubaid_autozoneoffers";
$username = "balubaid_autozoneoffers";
$password = "Vision@2050";

// Capture data
$ip = $_SERVER['REMOTE_ADDR'];
$userAgent = $_POST['userAgent'] ?? '';
$city = "Unknown"; // Default value

// Get city information based on IP using a public API
$geoData = @file_get_contents("http://ip-api.com/json/{$ip}");
if ($geoData) {
    $geoData = json_decode($geoData, true);
    if (isset($geoData['city'])) {
        $city = $geoData['city'];
    }
}

// Save data to database
try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $pdo->prepare("INSERT INTO whatsapp_clicks (ip_address, user_agent, city) VALUES (?, ?, ?)");
    $stmt->execute([$ip, $userAgent, $city]);

    echo json_encode(["status" => "success", "message" => "Click recorded."]);
} catch (PDOException $e) {
    echo json_encode(["status" => "error", "message" => $e->getMessage()]);
}
?>