How can PHP be used to control the navigation flow between different pages, such as returning to the original page after printing?

To control the navigation flow between different pages in PHP, you can use the header() function to redirect the user back to the original page after printing. This can be achieved by storing the original page URL in a session variable before navigating to the print page, and then redirecting back to that URL after the print operation is completed.

<?php
// Start the session
session_start();

// Store the original page URL in a session variable
$_SESSION['original_page'] = $_SERVER['HTTP_REFERER'];

// Perform the print operation
// Example: echo "Printing...";

// Redirect back to the original page
header('Location: ' . $_SESSION['original_page']);
exit;
?>