What are some best practices for refreshing a page in PHP after executing a code in a new window?

When executing a code that opens a new window in PHP, you may want to refresh the original page after the code has been executed in the new window. To achieve this, you can use JavaScript to refresh the page once the new window is closed. This can be done by adding a script in the new window that triggers a refresh function in the original window upon closing the new window.

// PHP code to open a new window and refresh the original page after executing a code

// Open a new window with the code execution
echo '<script>window.open("new_window.php", "_blank");</script>';

// JavaScript function to refresh the original page upon closing the new window
echo '<script>
        window.onunload = function(){
            window.opener.location.reload();
        };
      </script>';