How can the use of exit(); after header() in PHP scripts impact code execution flow?

Using exit(); after header() in PHP scripts can cause issues because exit(); terminates the script immediately, preventing any further code execution. This means that any code after the exit(); statement, including important cleanup tasks or additional logic, will not be executed. To solve this issue, you can rearrange your code so that the header() function is called after all necessary processing has been completed.

// Incorrect usage of exit() after header()
header('Location: new_page.php');
exit();

// Correct usage of header() before exit()
// Perform necessary processing here
// Then redirect to new_page.php
header('Location: new_page.php');
exit();