How can PHP be used to dynamically include different templates based on the user agent of the browser?

To dynamically include different templates based on the user agent of the browser, you can use PHP to detect the user agent and then include the appropriate template file based on the detected user agent. This can be useful for serving different layouts or stylesheets tailored to different devices or browsers.

<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($user_agent, 'iPhone') || strpos($user_agent, 'Android') || strpos($user_agent, 'Mobile')) {
    include 'mobile_template.php';
} else {
    include 'desktop_template.php';
}
?>