Forums | MacLife
You are not logged in.
#1 2008-03-12 11:41 pm
Detecting an iPhone?
So I thought it would be fun to experiment with making a site designed for the iPhone and looked up a few examples of how to detect the iPhone user agent. I tried to do this in JavaScript and in PHP but neither seemed to work. Anyone have any insight as to why this won't work?
PHP:
Code:
<?php
$browser = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone")
if ($browser)
{
echo 'You are using an iPhone';
}
else
{
echo 'You are not using an iPhone';
}
?>MacBook Pro 15.4"
2.5GHz CPU, 250GB HDD, 512MB VRAM
Offline
#2 2008-03-17 3:33 pm
- thumbprint
- giant member

- Registered: 2003-06-22
- Posts: 164
- Website
Re: Detecting an iPhone?
Sorry I don't have the answer, but am interested in finding out, too...
I do know that Apple just recently released an iPhone SDK and some of it pertains to web developers. I haven't been able to look through the SDK because it's only compatible with Leopard (I've got Tiger).
http://developer.apple.com/iphone/program/
Last edited by thumbprint (2008-03-17 3:35 pm)
=================================
I'm sorry I need this DISCLAIMER:
=================================
All my opinions are just that. Opinions. Chances are you won't agree. Chances are they won't apply to you. Even if we're arguing I'll still try to respect your opinions.
Offline
#3 2008-03-17 6:12 pm
Re: Detecting an iPhone?
Is your server using php5?
Try strpos() instead of stripos().
Offline
#4 2008-03-18 8:24 am
Re: Detecting an iPhone?
Code:
echo 'You are '. (strpos($_SERVER['HTTP_USER_AGENT'],"iPhone") ? '' : 'not ') . 'using an iPhone.';
Don't they teach you kids to code efficiently, these days?
Sheesh.
.tsooJ
Offline
#5 2008-03-19 1:22 am
Re: Detecting an iPhone?
Ternaries are for pussies. 
So, just when did this place get Private Messages? YIKES!
Gippy Pages | Fuzzy Coconut XHTML Widget | PuppyCam
Offline
#6 2008-03-19 6:13 am
Re: Detecting an iPhone?
I'm a mathematician and a programmer. Nested single line statements give me a boner. 
.tsooJ
Offline



