Forums | MacLife

You are not logged in.

#1 2008-03-12 11:41 pm

PHUSMC
One thumbed gimpy
From: Kent, WA
Registered: 2006-05-14
Posts: 821
Website

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

matt
Screw it
Registered: 1999-09-16
Posts: 16473
Website

Re: Detecting an iPhone?

Is your server using php5?

Try strpos() instead of stripos().

Offline

 

#4 2008-03-18 8:24 am

Alien
FF
Administrator
From: Republic of Amsterdam
Registered: 1999-07-05
Posts: 16609
Website

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

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9938
Website

Re: Detecting an iPhone?

Ternaries are for pussies. wink


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

Alien
FF
Administrator
From: Republic of Amsterdam
Registered: 1999-07-05
Posts: 16609
Website

Re: Detecting an iPhone?

I'm a mathematician and a programmer. Nested single line statements give me a boner. tongue

.tsooJ

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson