3

Is there an easy way to check via php or javascript whether it's "my iPad". Basically, I'd like to do some mobile testing and hope to use a function:

if (itsMine()){
    //do stuff
}

(I know that one way would be to check the ip address, but it would be great if there were something ipad specific)

karthikr
  • 97,368
  • 26
  • 197
  • 188
Eric
  • 1,209
  • 1
  • 17
  • 34
  • Do you want to check if it's your iPad or an ipad in general? If it's to check if it's your iPad I would check your ipad's UDID and use that as an identifier – Kevin Lynch May 14 '13 at 20:02
  • @Vector, if that is indeed a good way - it should be an answer, rather than a comment if you explain it a bit further :) – Moo-Juice May 14 '13 at 20:05
  • If you could elaborate on the UDID method, then it may be the solution that I was looking for. – Eric May 14 '13 at 20:19

5 Answers5

3

I'd setup a, possibly secured, page that sets/unsets a unique Cookie and use that to determine whether it's "you" or not.

Anthony Sterling
  • 2,451
  • 16
  • 10
  • I like this solution and it's how I've solved some testing issues for non-mobile stuff. However, if there is an iPad specific way of doing this (UDID as mentioned above?), then I can turn this into a learning experience as well. – Eric May 14 '13 at 20:19
1

I'm not familiar with the iPad, but I would be surprised, scratch that, I'd be flabbergasted if there was such an option.

Such an option would mean any iPad would be individually trackable without the owners consent or knowledge. If there was such an option it woild not remain for long.

Your best option is to use cookies. Create a page on your site that leaves a specific cookie on the device and test for it.

Eli Algranti
  • 8,707
  • 2
  • 42
  • 50
  • Thank you for your input. However, I was under the impression that if you lose your iPad and have paid Apple some sort of fee, that they can track it for you; it was this idea that led me to think that there's a unique "id" that I as an owner could access. – Eric May 14 '13 at 21:30
  • @Eric: If apple is charging people for that service, I'd be stunned to find out you could write some code that does, basically, the same thing for free. If apple can track your device, the code that does that will probably be buried deep in the inaccessible nooks and crannies of the iOS system – Elias Van Ootegem May 14 '13 at 21:39
  • OK! I guess I'll go back to the good ol' cookie approach as suggested by Anthony Sterling and Eli here. – Eric May 14 '13 at 21:52
  • @Eric: Just thought of something. Find My iPad works with your appleID... doesn't apple offer some sort of API which enables you to use that? Try the docs for phonegap. It's a bit of a faff, but it might just be what you're looking for! – Elias Van Ootegem May 14 '13 at 22:16
  • Thanks for the additional thought; however, if it's not quick and easy, I think that I'll still stick with "cookies". :) – Eric May 15 '13 at 13:15
0

You could use a 3rd party non-safari browser that allows you to set the user agent. Set it to some unique value, and check it with JavaScript PHP.

Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
  • 1
    ... of course you'll want to do the actual validation of the user agent on the server side; otherwise anyone could just look at your javascript and set their user agent to the value there. – user428517 May 14 '13 at 20:07
0

There's no foolproof way of checking for this, without resorting to usernames and passwords. The closest you'll get is a combination of IP address and user agent ($_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_USER_AGENT']). However you should bear in mind, that whilst they may be okay for your needs, they are not foolproof and can be spoofed, and therefore should not be relied on where security is an issue.

VettelS
  • 1,204
  • 1
  • 9
  • 17
  • IP addresses can also change. Your iPad will have a different IP when you use it from home and at a hotspot. – Barmar May 14 '13 at 19:58
  • @VettelS I always thought that's how it was spelled too, then someone pointed it out for me :) – Ian May 14 '13 at 20:05
-1

Use a hashtag. You call for it by putting #mine after the URL.

if(location.hash == "#mine") {
  // do something
}
Qvcool
  • 460
  • 3
  • 10
  • how does this answer the question at all?? – user428517 May 14 '13 at 20:04
  • 1
    When people talk about a _"hash"_ to verify the validity of something, they don't mean `#`, they mean an algorithm that produces a checksum: [check the wiki for more info](http://en.wikipedia.org/wiki/Hash_function) – Elias Van Ootegem May 14 '13 at 20:06
  • @sgroves It will run a function if your specify it. Although this can be done by anyone, since JavaScript is run client-side, it would not matter. – Qvcool May 14 '13 at 20:10
  • 1
    yeah, i get what you're trying to do, i guess, but this is an incredibly half-baked solution. like you said, anyone could look at the javascript and figure out they can add `#mine` to the url to break in. – user428517 May 14 '13 at 20:15
  • @sgroves JavaScript is run client-side, so you could manually run the function, and also, I don't think detecting whether or not it is "my iPad" will be permanent. – Qvcool May 14 '13 at 20:24