Is there a way to detect if the user is using a tablet or a phone?
As an example a person surfing the web using a tablet (any android tablet with version 3+ and iPad) they
You can use something like Device Atlas to detect these features off the User Agent. The offer an API that you can host yourself, and they also offer a cloud service. Both are premium (paid-for)
Alternatively you can use something like Wurfl which, in my experience, is less accurate.