Search code examples
phphtmlcssbrowser-detection

How do one use Mobile_Detect.php for a web form?


I am currently a beginner developing a web form and I am stuck on the mobile support stuff and I came across this php code: Mobile_Detect.php

How do I use it on make my form?


Solution

  • If it is an styling issue there are different ways to archive what you want:

    If you really want to use Mobile_Detect you can do something like this:

    require_once 'Mobile_Detect.php';
    $detect = new Mobile_Detect;
    if($detect->isMobile()){ /* include mobile.css */ } 
    else if($detect->isTablet()){ /* include "tablet.css" */ }
    else { /* include "desktop.css" */ }
    

    But in my mind there is no need to use PHP in this case. You don't need to know WHAT kind of device the user is using since the styling issues are usually related to the screen dimensions. In CSS you can use Media Querys like this:

    @media (min-width:320px) { /* smartphones, portrait iPhone */ }
    @media (min-width:480px) { /* smartphones, landscape iPhone */ }
    @media (min-width:600px) { /* portrait tablets */ }
    @media (min-width:801px) { /* landscape tablets */ }
    @media (min-width:1025px) { /* laptops, and desktops */ }
    @media (min-width:1281px) { /* large laptops and desktops */ }
    

    Inside the querys you can overwrite CSS properties that are only used if the screen dimension is in the given range. A very smart solution I think!