How can PHP be used to redirect users to a mobile version of a website on a subdomain?
To redirect users to a mobile version of a website on a subdomain using PHP, you can detect the user's device type (such as a mobile device) and then redirect them to the mobile version on a subdomain. This can be achieved by checking the user agent string and then using the header() function to redirect the user to the mobile subdomain.
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($user_agent, 'Mobile') !== false) {
header('Location: https://m.yourwebsite.com');
exit();
}
?>