View Single Post
ישן 05-12-15, 00:52   # 3
Programnnd
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Feb 2011
הודעות: 143

Programnnd לא מחובר  

שימוש קטן בPREG_MATCH יכול לפתור את זה ברמת php:
קוד:
// Create the function, so you can use it
function isMobile() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
// If the user is on a mobile device, redirect them
if(isMobile()){
    header("Location: http://m.yoursite.com/");
}
פונקציה לפתור את זה ברמת JS:
קוד:
var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};

//use
if(isMobile.any()) {
   alert("This is a Mobile Device");
window.location.href = 'http://www.site.com/';
}
וזה סקריפט מוכן שראיתי ברשת :
קוד:
function mobileDevice()
{
$type = $_SERVER[‘HTTP_USER_AGENT’];
if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false)
return true;
else
return false;
}
if(mobileDevice() == true)
header(‘Location: http://www.m-tek.biz/mobile.html‘);
__________________
XHTML - CSS3 - BOOSTRAP - JQUERY - AJAX - PHP - SQL - SECURITY SQL
benworksites@gmail.com


  Reply With Quote