Advertisement
Guest User

Server-side detection of CSS3 Gradients

a guest
Feb 13th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. /**
  2.  * Attempts to ascertain user agent support for CSS-based gradients.
  3.  *
  4.  * @version 1.1
  5.  * @param string $ua UA string to analyse. Defaults to the current User-Agent.
  6.  * @return bool True if browser appears capable of supporting CSS gradients.
  7.  */
  8. function gradient_support($ua = ''){
  9.     $agent      =   empty($ua) ? $_SERVER['HTTP_USER_AGENT'] : (string) $ua;
  10.  
  11.     //  Gecko 1.9.2
  12.     if(preg_match("#(Firefox|Thunderbird|Fennec)\/([\w\.]+)#", $agent, $match)){
  13.         switch($match[1]){
  14.             case 'Firefox' : return(version_compare('3.6', $match[2]) < 1);     break;
  15.             case 'Thunderbird' : return(version_compare('3.1', $match[2]) < 1); break;
  16.             case 'Fennec' : return(version_compare('1.0a1', $match[1]) < 1);    break;
  17.         }
  18.     }
  19.  
  20.     //  Chrome (Apparently supported in all builds)
  21.     else if(preg_match("#Chrome\/#", $agent, $match))
  22.         return true;
  23.  
  24.  
  25.     //  Safari 4.0
  26.     else if(preg_match("#Safari\/#", $agent, $match) && preg_match("#Version\/([\w\.]+)#", $agent, $match))
  27.         return(version_compare('4.0', $match[1]) < 1);
  28.  
  29.  
  30.     //  Internet Explorer 10.0
  31.     else if(preg_match("#MSIE ([\w\.]+)#", $agent, $match))
  32.         return(version_compare('10.0', $match[1]) < 1);
  33.  
  34.  
  35.     //  Presto 2.8+ (Opera 11.10)
  36.     else if(preg_match("#Presto\/([\w\.]+)#", $agent, $match))
  37.         return(version_compare('2.8', $match[1]) < 1);
  38.  
  39.     return false;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement