php - Detect client using site in mobile -


this question has answer here:

can detect client's operating system using php, mobile, android or windows display site's design responsive.

i have used,

css

@media screen , (min-width: 1200px) {      /*          detected pc.      */ } @media screen , (min-width: 500px) {      /*          detected mobile or pc.      */ } 

but don't want write both css in same page , wanted load them php

php

<?php     $is_pc = ???; //don't know write.     if ($is_pc) {        echo '<link href="pc.css" rel="stylesheet">';     } else {        echo '<link href="mobile.css" rel="stylesheet">';     } ?> 

bad practice , main, far one, :

if choose witch css load server side, you'll not able handle switch on tablet between vertical , horizontal mode (hz = desktop view; vt = mobile one), you'll not have reload of page.

this why should load both media query in css @ same time.


if want make same behaviour, use :

<link rel="stylesheet" media="screen , (max-width: 768px)" href="mobile.css" /> <link rel="stylesheet" media="screen , (min-width: 768px)" href="pc.css" />  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -