Here is some information from a similar question:
Auto detect mobile browser (via user-agent?)
It involves reading the user-agent header. The answers to that other question include links for scripts for this.
Here is another helpful discussion:
Standard way to detect mobile browsers in a web application based on the http request