Question

I am currently checking if a device is an iPad or not using the following code

if(stristr($_SERVER['HTTP_USER_AGENT'], 'Mozilla/5.0(iPad;')) {
    // probably an iPad
}

It is reliable enough for my needs. I need to detect whether it is an iPad 1, 2 or 3.

I have searched and can not find an answer that is php based. I tried to search for distinct user agent strings but people are suggesting they are all the same for the iPad model, but different per iOS and safari version, not per iPad model.

Was it helpful?

Solution

On the server side you are only going to get the details posted to you by the client agent. So effectively only the user-agent string which does change and as you say shouldn't be relied upon for the iPad model.

What you will need to do is execute some check on the iPad itself, such as pushing down a bit of Javascript that will check the model and then re-direct or send data back to your server saying the iPad model number.

There seems to be a few ways to do it in Javascript, but this will not be in PHP as like I say, the server, by default is only sent the HTTP headers which do not have the necessary information to categorically know the iPad model number. You will need to run something on the client to figure this out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top