Web Develop Forum: iPhone/iPod Touch mobile device detection - Web Develop Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

iPhone/iPod Touch mobile device detection Rate Topic: -----

#1 User is offline   thinglie Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 41
  • Joined: 25-October 08
  • Gender:Male
  • Location:House

Posted 08 February 2009 - 01:15 PM

This little snippet detects whether or not the user is on an iPhone/iPod.

CODE
// Are we on an Apple iPOD?
if ((strstr($_SERVER['HTTP_USER_AGENT'], "iPhone")) || (strstr($_SERVER['HTTP_USER_AGENT'], "iPod"))) {
// your code here
}

<a href="http://www.gnu.org/" target="_blank"><img src="http://www.gnu.org/graphics/gnubanner-2.png" border="0" class="linked-sig-image" /></a>
<a href="http://www.fsf.org'" target="_blank">Free Software Foundation</a>
0

#2 User is offline   Salathe Icon

  • Advanced Member
  • Icon
  • Group: Moderator
  • Posts: 138
  • Joined: 15-January 09
  • Gender:Male
  • Location:Scotland

Posted 09 February 2009 - 12:27 AM

This idea could be wrapped in a little function, something like:
http://pastie.org/38...jrqk5c5fzjd9mpq
(Pastied since the code bbcode doesn't preserve formatting properly)
salathe@php.net
0

#3 User is offline   Sam Granger Icon

  • Administrator
  • PipPipPip
  • Group: Root Admin
  • Posts: 431
  • Joined: 22-October 08
  • Gender:Male

Posted 09 February 2009 - 10:38 AM

Thanks guys! This will come into use! smile.gif
0

#4 User is offline   thinglie Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 41
  • Joined: 25-October 08
  • Gender:Male
  • Location:House

Posted 12 February 2009 - 05:18 PM

QUOTE (Peter @ Feb 9 2009, 12:27 AM) <{POST_SNAPBACK}>
This idea could be wrapped in a little function, something like:
http://pastie.org/38...jrqk5c5fzjd9mpq
(Pastied since the code bbcode doesn't preserve formatting properly)


A bit long-winded, perhaps... maybe just:

CODE
function is_iphone() {
if ((strstr($_SERVER['HTTP_USER_AGENT'], "iPhone")) || (strstr($_SERVER['HTTP_USER_AGENT'], "iPod"))) {
return TRUE;
} else { return FALSE; }
}

<a href="http://www.gnu.org/" target="_blank"><img src="http://www.gnu.org/graphics/gnubanner-2.png" border="0" class="linked-sig-image" /></a>
<a href="http://www.fsf.org'" target="_blank">Free Software Foundation</a>
0

#5 User is offline   Salathe Icon

  • Advanced Member
  • Icon
  • Group: Moderator
  • Posts: 138
  • Joined: 15-January 09
  • Gender:Male
  • Location:Scotland

Posted 12 February 2009 - 07:39 PM

Sure, if you want to go ultra-simple:
CODE
function is_iphone() {
    return (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod'));
}


Note: The function body should be all one line, the forums seem to wrap it onto two.
salathe@php.net
0

#6 User is offline   Will Roberts Icon

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 64
  • Joined: 23-October 08
  • Gender:Male
  • Location:Buckley, North Wales

Posted 13 February 2009 - 12:30 PM

You could also do the following.

CODE
<!--#if expr="(${HTTP_USER_AGENT} = /iPhone/)"-->
     <style type="text/css">
     <!--
     iPhone styles
     -->
     </style>
<!--#else -->
    <style type="text/css">
    <!--
    normal styles
    -->
    </style>
<!--#endif -->


My Portfolio: <a href="http://www.imagelimited.co.uk" target="_blank">I.M.A.G.E</a>
Submit Your Site: <a href="http://www.keepittidy.co.uk" target="_blank">K.I.T</a>
CSS & XHTML Tutorials: <a href="http://www.fatbasturd.co.uk" target="_blank">FatBasturd</a>
SEO Services: <a href="http://www.firstplaceingoogle.com" target="_blank">Firstplaceingoogle.com</a>
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users