Monday, March 21, 2016

Check OS and Browser Agent with PHP




The user agent string is a text that the browsers themselves send to the webserver to identify themselves, so that websites can send different content based on the browser or based on browser compatibility.

Mozilla is a browser rendering engine (the one at the core of Firefox) and the fact that Chrome and IE contain the string Mozilla/4 or /5 identifies them as being compatible with that rendering engine.

In this case I will show you how to detect the Os or Browser Agent using PHP ,

* Check OS
$agent = $_SERVER['HTTP_USER_AGENT'];
// get os
if (preg_match('/linux/i', $agent)) {
    $os = 'linux';
} elseif (preg_match('/macintosh|mac os x/i', $agent)) {
    $os = 'mac';
} elseif (preg_match('/windows|win32/i', $agent)) {
    $os = 'windows';
}

* Check Browser Agent
if (preg_match('/Chrome/i', $agent)) {
    if ($os == 'windows') {
        //impleted;
     } else {
        //impleted;
     }
} elseif (preg_match('/Firefox/i', $agent)) {
   if ($os == 'windows') {
      //impleted;
   } else {
     //impleted;
   }
} elseif (preg_match('/Safari/i', $agent)) {
   if ($os == 'windows') {
      //impleted;
   } else {
      //impleted;
   }
}
- Let's enjoy!

1 comment:

  1. 1XBet
    Betting in India. It can be 바카라사이트 great to find septcasino.com the most popular brands, especially gri-go.com ones https://septcasino.com/review/merit-casino/ that offer betting on sports such as football, tennis,  Rating: 1/10 1xbet 먹튀 · ‎Review by Riku VihreasaariWhere can I find 1xbet?Where can I find 1xbet betting?

    ReplyDelete