Reputation: 22822
I see that mobile versions of websites often begin with an "m." (e.g. http://m.accuweather.com). I'd like to redirect my mobile users to http://m.mysite.com
so that I can display a different page.
Upvotes: 1
Views: 2354
Reputation: 11
the simplest method i used to detect mobile devices or otherwise using php
but I used strcontains on php>8
this is the function i created
<?php
function Ismobile($mobile, $notmobile)
{
$device_Info = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strstr($device_Info, 'mobile'))
{
echo $mobile;
}
else
{
echo $notmobile;
}
}
Ismobile('it is a mobile device', 'this is not a mobile device');
?>
https://shopinson.com/php/how-to-detect-a-mobile-device-using-php/ shows the article i created which explains more about including the php>8 function for detecting mobiles
Upvotes: 0
Reputation: 1804
I would do this client-side. There is no need to give extra load on your server for this. It can be done through JavaScript or jQuery (and there are many tutorials for this). For example:
http://detectmobilebrowsers.com/
Auto detect mobile browser (via user-agent?)
Feeding can be done trough the new mobile tags (or the @media) and some nice clean HTML5. For example:
http://www.html5rocks.com/en/mobile/mobifying.html
http://webdesign.about.com/od/mobile/a/detect-mobile-devices.htm
Upvotes: 1
Reputation: 318478
The easiest way is checking the user agent, available via $_SERVER['HTTP_USER_AGENT']
. While clients can send any string, people usually do not pretend to be a mobile browser if they aren't (and if they do so - not your problem).
Upvotes: 3