If you are in need of a great way to detect if a mobile or tablet is viewing your site I suggest looking at the MobileESP project. SITE Link - MobileESP
The project has both downloadable scripts for most languages and also a rich API that can be used. The API allows for the ablity to have new devices be added without re-compiling or addressing code.
Thank you to the MOBILEesp team.