How to detect WAP browser and redirect to different url in PHP

Detect WAP browser and redirect to different url in PHP:

<?php

$htmlredirect = "http://www.artofmobile.com/index.html";
$wmlredirect = "http://www.artofmobile.com/index.wml";

$br='html';

if(preg_match("/wap/i",$HTTP_ACCEPT)) {

   $br = "wml";
}

if($br == "wml") {
   header("302 Moved Temporarily");
   header("Location: ".$wmlredirect);
   exit;
}

header("302 Moved Temporarily");
header("Location: ".$htmlredirect);

?>