How can header() function be effectively utilized in PHP to redirect users to different pages based on certain conditions?

To redirect users to different pages based on certain conditions in PHP, the header() function can be effectively utilized. By setting the "Location" header to the desired URL, the user's browser will automatically redirect to the specified page. This can be useful for scenarios such as redirecting users after a successful login or based on certain criteria being met.

<?php
// Check a condition
if ($condition_met) {
    header("Location: new_page.php");
    exit;
} else {
    header("Location: default_page.php");
    exit;
}
?>