// Function to collect user data and send it via AJAX
function sendUserInfo() {
    var userInfo = {
        platform: navigator.platform,              // Device platform (e.g., Windows, Linux, etc.)
        userAgent: navigator.userAgent,            // User's browser details
        language: navigator.language,              // Browser language
        screenResolution: window.screen.width + "x" + window.screen.height, // Screen resolution
        colorDepth: window.screen.colorDepth,      // Screen color depth
        timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, // User's timezone
        referrer: document.referrer,                // Referring URL (if any)
        url: window.location.href                  // Current page URL
    };

    // AJAX request to send the data to PHP
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "store_user_info.php", true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    // Prepare data to send as a query string
    var data = "platform=" + encodeURIComponent(userInfo.platform) +
               "&userAgent=" + encodeURIComponent(userInfo.userAgent) +
               "&language=" + encodeURIComponent(userInfo.language) +
               "&screenResolution=" + encodeURIComponent(userInfo.screenResolution) +
               "&colorDepth=" + encodeURIComponent(userInfo.colorDepth) +
               "&timezone=" + encodeURIComponent(userInfo.timezone) +
               "&referrer=" + encodeURIComponent(userInfo.referrer) +
               "&url=" + encodeURIComponent(userInfo.url);

    // Send data to the PHP script
    xhr.send(data);
}

// Call the function when the page loads
window.onload = function() {
    sendUserInfo();
};
