title: User agent in php
body: <p>I'm trying to get a little script working. It shouldn't be hard, but I'm kind of a n00b when it comes to PHP (my last experiments were many years ago).</p>
  
  <p>So, basically, I want a little script that IF the client uses a mobile device, it gives a link to Facebook as an app link. IF the client has a regular laptop, the script should output a regular Facebook.</p>
  
  <p>Okay, so I'm just going to show my screwed up code, to make it (hopefully) more clear what I'm trying (some might notice that I grabbed part of the code from another thread):</p>
  
  <pre><code>&lt;?php
  function check_user_agent ( $type = NULL ) {
          $user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
              if ( $type == 'mobile' ) {
                      if ( preg_match ( "/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
                          echo "fb://groups/334257489999204";
                      } else if ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap /", $user_agent ) ) {
                          echo "fb://groups/123456789";
                      }
          }
          else {
              echo "https://www.facebook.com/groups/123456789";
          };
          echo "https://www.facebook.com/groups/123456789";
  };
  ?&gt;" /&gt;
  </code></pre>
  
  <p>This code is in a html anchor href tag, inside a .php file (mainly HTML though).</p>
  
  <p>Thanks!</p>