The following is an example of how to determine whether the website is accessed by php android, ios or wp. I hope it will be useful to you. Friends it will be helpful.
In php, you can use $_SERVER['HTTP_USER_AGENT'] to distinguish whether it is an android, ios or wp request. Specifically, you can use the following code to achieve it:
$userAgent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match("/(iPod|iPad|iPhone)/", $userAgent))
{
echo 'ios'; //IOS client
}
elseif (preg_match("/WP/", $userAgent))
{
echo 'wp'; //WinPhone client
}
elseif (preg_match("/android/i", $userAgent)) {
echo 'android'; //android client
}
Of course, I can also add a piece of js code to the head of the web page and the effect will be the same.
In this way, as long as you access the website from your mobile phone, you will automatically reach the mobile version of the website