
<!DOCTYPE html>
<html>
<head>
    <title>Confirm</title>
</head>
<body>


            <?php 
            include "../database/database.php";
            include "../database/data.php";

            session_start();

            // Check if the browser ID is already stored in the session
            if (isset($_SESSION['browser_id'])) {
                $browserId = $_SESSION['browser_id'];
            } else {
                // Generate a new browser ID
                $browserId = generateUniqueBrowserId();

                // Store the browser ID in the session for future use
                $_SESSION['browser_id'] = $browserId;
            }
            $b_id = $browserId;


            $sql = "SELECT * FROM ".$user_database." WHERE browser_id='$b_id'";
            $result = $connection->query($sql);
            if ($result && $result->num_rows > 0) {
                $query = "UPDATE ".$user_database." set browser_id='0' where browser_id='$b_id'";
                if (!$connection->query($query)) {
                    die("ERROR: Query failed. " . $connection->error);
                }
                else{ 
                    echo '<script>window.location = "login_user.html";</script>';
                }
                
            } 

            function generateUniqueBrowserId()
            {
                $randomString = bin2hex(random_bytes(16));
                $timestamp = time();

                return $randomString . $timestamp;
            }
?>

</body>
</html>


