Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bonskovsky

macrumors 6502
Original poster
Dec 31, 2012
453
2
I have a website that I'm making, but I only want it to work on iPhones, specifically the iPhone 5. I want an error message to show whenever someone tries to use an Android phone or computer to view the website.

What kind of code can I use to make this happen?
 
Last edited:

Squilly

macrumors 68020
Nov 17, 2012
2,260
4
PA
Java? Enable a pop-up that prevents anything but 6,1 (iPhone code name) from accessing the site.
 

Jman13

macrumors 68000
Aug 7, 2011
1,570
277
Columbus, OH
Why? To intentionally restrict your audience? That's like Apple coming out with a great product that can only be purchased in New York by women aged 23-30.
 

Interstella5555

macrumors 603
Jun 30, 2008
5,219
13
No sure why you would want to do this, but there should be a way to identify the browser/device and throw up an error message.
 

bonskovsky

macrumors 6502
Original poster
Dec 31, 2012
453
2
I'm testing this new game, it can only work on iPhones. There's a reason to do this.

Just to see if it works, I feel like I'd need to edit the code that it uses to detect whether or not it's a mobile phone to begin with.
 

Interstella5555

macrumors 603
Jun 30, 2008
5,219
13
I'm testing this new game, it can only work on iPhones. There's a reason to do this.

Just to see if it works, I feel like I'd need to edit the code that it uses to detect whether or not it's a mobile phone to begin with.

Just remember you'll need to block out desktop versions off all browsers as well as the associated OSs as well.
 

bonskovsky

macrumors 6502
Original poster
Dec 31, 2012
453
2
somehow, the code that i'm using automatically goes to mobile if on a mobile. so i just have to edit a little bit more code to make it more direct
 

Brian Y

macrumors 68040
Oct 21, 2012
3,776
1,064
Just do a quick check of the referrer, and possibly the screen resolution too.

But remember these can all be faked - there's no known way to restrict to certain browsers/platforms that can't be circumvented.
 

Plutonius

macrumors G3
Feb 22, 2003
9,032
8,404
New Hampshire, USA
I'm testing this new game, it can only work on iPhones. There's a reason to do this.

Just to see if it works, I feel like I'd need to edit the code that it uses to detect whether or not it's a mobile phone to begin with.

Let everyone into the site but mention on the site that Android users are out of luck if they want to play the game. They should upgrade their Android phone to an iPhone :).
 

Mrbobb

macrumors 603
Aug 27, 2012
5,009
209
The browser making request to ur page customarily sends that information to u.
 

macsrcool1234

Suspended
Oct 7, 2010
1,551
2,130
I'm not aware of what web feature would work on iPhone 5's and nothing else but the easiest way to do this is to check the user agent string and only accept the iPhone 5's. This is relatively easy to bypass but gets the job done.
 

tom71441

macrumors newbie
Jan 17, 2013
1
0
Use the 'User-Agent' property from the request header.

Look for ipad or iphone in the string.
Like
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16

I use regex just to match against iphone, so i don't have to worry about all the other version stuff


Just do a quick check of the referrer, and possibly the screen resolution too.

But remember these can all be faked - there's no known way to restrict to certain browsers/platforms that can't be circumvented.
 

throAU

macrumors G3
Feb 13, 2012
8,817
6,985
Perth, Western Australia
I have a website that I'm making, but I only want it to work on iPhones, specifically the iPhone 5. I want an error message to show whenever someone tries to use an Android phone or computer to view the website.

What kind of code can I use to make this happen?

Don't be an idiot.


Writing non-standards compliant websites is bad when it is for IE, and also bad when it is for apple gear.


Yes, you CAN do it with the user-agent string. Doing so is still bad.

edit:
If the game does not support android, put a disclaimer on the site. Don't just block access entirely.
 

Zac7

macrumors 6502a
Jan 9, 2011
712
14
Didn't think this guys threads could get better and he keeps proving me wrong.
 

bonskovsky

macrumors 6502
Original poster
Dec 31, 2012
453
2
Yeah and someone got rid of the iPhone-stupor thread. I guess they didn't think it was a real issue, which it is, I think.

I don't care about anyone bypassing it. The website just won't show up correctly. There are apps that only work with the 5, like the little panoramic vibration app.
 

Zac7

macrumors 6502a
Jan 9, 2011
712
14
Yeah and someone got rid of the iPhone-stupor thread. I guess they didn't think it was a real issue, which it is, I think.

I don't care about anyone bypassing it. The website just won't show up correctly. There are apps that only work with the 5, like the little panoramic vibration app.

So you thought it was a necessary issue to discuss why you sometimes forget why you went on your iPhone?
 

vastoholic

macrumors 68000
Jan 28, 2009
1,957
1
Tulsa, OK
Yeah and someone got rid of the iPhone-stupor thread. I guess they didn't think it was a real issue, which it is, I think.

I don't care about anyone bypassing it. The website just won't show up correctly. There are apps that only work with the 5, like the little panoramic vibration app.

I just read that thread. That is not an iPhone issue. That's a brain fart issue. User error. People experience it. Phones and inanimate objects do not experience that issue and it was not necessary to create a thread about it.
 

bonskovsky

macrumors 6502
Original poster
Dec 31, 2012
453
2
I still wanted to know why that happens to so many people. Because I think it's because of the way iOS is, is just a big long list of apps and they all look the same I just forget what I'm going to do.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.