add js or css depending on browser with php

add js or css depending on browser with php with the below short code:


<?=    (preg_match('/Safari/i',$_SERVER["HTTP_USER_AGENT"] )) ? 'body{line-height:1.2; margin:0;padding:0;} @media print { html, body { margin: 0; padding: 0; }' : '' ?>

Also you can do more with the below code

$u_agent = $_SERVER['HTTP_USER_AGENT'];
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";

//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
$platform = 'mac';
}
elseif (preg_match('/windows|win32/i', $u_agent)) {
$platform = 'windows';
}

if(preg_match('/Safari/i',$u_agent))
{
$bname = 'Apple Safari';
$ub = "Safari";
}
0

Leave a Reply

Your email address will not be published. Required fields are marked *

*