I got a function that works well, but i need to extend it a bit, and im not a programmer.
Now it can detect ios well, and android and web are both redirected to one page for both, web and android.
The goal is, to redirect ios to page 1, android to page 2 and web-os to page 3.
function find_mobile_browser() {
if(preg_match('/(iphone|ipad|ipod)/i', $_SERVER['HTTP_USER_AGENT'])) {
return true;
} else {
return false;
}
}
The call is this:
<?php $mobile_browser = find_mobile_browser();
if($mobile_browser) {
include("ios.php"); /* if mobile browser detected, do this */
} else {
include("android_and_web.php"); /* else do this */
}
?>
Can you help me to extend this snippet to detect it so, that the call can this:
<?php $mobile_browser = find_mobile_browser();
if($mobile_browser) {
include("ios.php"); /* if ios detected, do this */
} else {
include("android.php"); /* if android detected, do this */
}
} else {
include("web_os.php"); /* if web-os detected, do this */
}
?>
I think its not a perfect way to detect mobile devices, but is there a better one?
Thanks, Orwell
After your nice answers, i'll explain maybe better.
The "header" answer is useful for me, - but im not a programmer and so i dont get it to work how i want it to use. The redirection works well, but i need no redirections, i need includes. I want to include depending ios/android/web a little text snippet (the php-files) in some of my templates.
The function works well, but my call didnt show any result. Here ho i try to call the function:
<?php
$mobile_browser = find_mobile_browser();
if($mobile_browser == 'ios')
{
include("ios.php");
}
elseif ($mobile_browser == 'android')
{
include("android.php");
}
else
{
/* if no mobile os detected, include "web.php" */
}
?>
Hope im clearer now, and you are not to upset.
Thanks in advance, Orwell
Thanks for your greatfull answers, - i got it now :))
Cheers, Orwell