-1

I have a web site. I want to make the main page index.php which detects if the OS the user is running is mobile and redirects to a mobile site. How can I do this?

Mathio
  • 1
  • 3
  • Possible duplicate of https://stackoverflow.com/questions/13109770/best-way-to-redirect-single-php-page-for-mobile-devices-with-php-javascript – Flight Odyssey Oct 26 '17 at 00:09
  • 1
    Possible duplicate of [Best way to redirect single php page for mobile devices with PHP/Javascript](https://stackoverflow.com/questions/13109770/best-way-to-redirect-single-php-page-for-mobile-devices-with-php-javascript) – Johannes Müller Oct 26 '17 at 00:36

2 Answers2

0

You want to consider the user-agent header. Here's a very complete write up:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
0
<html><head>
<script type="text/javascript">
var device = navigator.userAgent
if (device.match(/Iphone/i)|| device.match(/Ipod/i)|| device.match(/Android/i)|| device.match(/J2ME/i)|| device.match(/BlackBerry/i)|| device.match(/iPhone|iPad|iPod/i)|| device.match(/Opera Mini/i)|| device.match(/IEMobile/i)|| device.match(/Mobile/i)|| device.match(/Windows Phone/i)|| device.match(/windows mobile/i)|| device.match(/windows ce/i)|| device.match(/webOS/i)|| device.match(/palm/i)|| device.match(/bada/i)|| device.match(/series60/i)|| device.match(/nokia/i)|| device.match(/symbian/i)|| device.match(/HTC/i))
{
window.location = "./mobile.php";
}
else
{
var page = "./desktop.php";         
top.location = page;
}
</script>
</head>
</html>
Mathio
  • 1
  • 3