How can PHP be used to refresh content within a frame after a user login?

To refresh content within a frame after a user login, you can use PHP to check if the user is logged in and then dynamically load the updated content into the frame using AJAX. This way, when the user logs in, the frame will automatically refresh with the new content without needing to reload the entire page.

<?php
// Check if user is logged in
if(isset($_SESSION['user_id'])){
    // Load updated content using AJAX
    echo '<script>
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    document.getElementById("frame_id").innerHTML = this.responseText;
                }
            };
            xhttp.open("GET", "updated_content.php", true);
            xhttp.send();
          </script>';
}
?>