This basic mobile_user_agent_switch() function will allow you to quickly check if mobile visitor is using one of the following devices.
SUPPORTED DEVICES
- iPhone
- iPad
- Android
- Blackberry
THE MOBILE_USER_AGENT_SWITCH() FUNCTION
The function will return one of the following values for you to work with in your code:
- ipad
- iphone
- blackberry
- android
- unknown
Hopefully this helps someone else out there!
LOOKING FOR MORE DETAIL?
This is only the tip of the iceberg. If you’re looking for a detailed mobile detection script I suggest checking out the mobile device detect script provided by detectmobilebrowsers.mobi.
It provides a more detailed check that will include:
- Windows Mobile Devices
- Palm Mobiles
- Opera Mini Devices
- Amazon Kindle
- Much more…
At the time this script was overkill for my needs, so I wrote the basic function above to provide a lean solution to suite my needs: A basic PHP function to check for major mobile devices.
RESOURCES
<?
$reDirectURL = "";
// 아이폰 앱스토어
$URL_IPHONE = "아이폰url";
// 구글 플레이
$URL_ANDROID = "구글플레이 url";
$iPod = stripos($_SERVER['HTTP_USER_AGENT'], "iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'], "iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'], "iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'], "Android");
if($iPod || $iPhone || $iPad ){
$reDirectURL = "Location:";
$reDirectURL .= $URL_IPHONE;
}
else if($Android){
$reDirectURL = "Location:";
$reDirectURL .= $URL_ANDROID;
}
header($reDirectURL);
exit();
?>
'Development > PHP' 카테고리의 다른 글
php - 유용한 함수 (0) | 2013.05.23 |
---|---|
php - 기본 문법 (0) | 2013.05.17 |
php - syslog (0) | 2013.05.15 |
php - PDT 설치 (0) | 2013.05.13 |
php - mail() 함수 사용시 한글 깨짐 문제 (0) | 2013.04.06 |