recognizing client device size

recognizing client device size

I am building a singular jquery- mobile application that is accessed by Desktop-browsers, Tablets/iPad, Mobile-browsers (big screens) and mobile devices (smaller screens). I want to discard any mobiles that are too small (say smaller than a defined width and height, were I will show a not compatible message).

So this takes me to 4 categories:

1. Desktop

2. Tablet.

3. Smartphones with big screens.

4. Smartphones with smaller screens.

5. Smaller than 4th category which I will discard with an error message.

Is there any example code that I can write in PHP to know where the request is coming from?

I want to build 4 sets of images and based on the category, send the appropriate images and font sizes while responding with the content.

I am a beginner and am very sure that this is a common problem with solution crafted in a design pattern that you all follow. Where can I find it?