How can PHP be used to dynamically redirect users to different pages based on their input URL?

To dynamically redirect users to different pages based on their input URL in PHP, you can use the header() function to send a raw HTTP header to perform the redirection. You can check the input URL using $_GET or $_POST superglobals and then use conditional statements to determine the destination URL for redirection.

<?php
$input_url = $_GET['url'];

if ($input_url == 'page1') {
    header('Location: page1.php');
    exit;
} elseif ($input_url == 'page2') {
    header('Location: page2.php');
    exit;
} else {
    header('Location: error.php');
    exit;
}
?>