Search code examples
phpmedia-queriesconditional-statements

PHP conditions depending on window width (media queries?)


I have a responsive website and I need some PHP conditions depending on the windows width (or media queries).

Example:

if ($window_width > 1400px) {
    echo 'Your window is wider than 1400px';
}

elseif ($window_width > 1000px) AND ($window_width < 1399px) {
    echo 'Your window is between 1000px and 1399px';
}

else {
    echo 'Your window is narrower than 1000px.';
}

Thanks for your help!


Solution

  • check this

    Goolgle Mobile Detect

    Try to use http://www.php.net/get_browser and check for isMobileDevice field. It might help only, of course, if the path to browscap.ini is set up in php.ini. If not, you can use php classes like https://github.com/garetjax/phpbrowscap