Don’t follow the advice posted below to “optimize” your site based on the user agent string. The author suggests doing so in the page.tpl.php for your theme. However, this means you can NEVER turn caching on for your site. Also, the uses ereg functions to “detect” the device. These functions are now deprecated by PHP, meaning they won’t be supported in the future. The matches used are also very simple, and could be done much faster using the strpos or stripos functions.
Optimise your Drupal website for a iPhone or iPod
If you need to detect the useragent, you should probably use hook_init() or hook_boot() to do so, since they run regardless of the cache settings. You’d also have to plan more thoroughly how to react to different devices – if in fact you thinkg that’s a good solution. A better approach would be to use pretty clean, flexible markup and use CSS media queries to provide device-specific stylesheets, as in Return of the Mobile Stylesheet.