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

BevvyB

macrumors member
Original poster
Jun 3, 2003
32
0
Is there a way to have your site spot an iPhone and redirect accordingly?
ALSO
Has anyone created a 'basic iPhone template' out there to get started for the less technical of us - html and css
Cheers
B
 
Query the user agent header in the request for the iPhone's browser. (iPhone; U; CPU like Mac OS X; en)

http://developer.apple.com/iphone/

If you're doing QT, use a container movie to point to separate desktop, WiFi, and EDGE versions.

I'm pulling my hair out trying to figure this out too. Is there a way you can write out the script for us newbies?

I have looked all over, and come up empty. Basically, when the iPhone surfs to my site, it automatically redirects to my iPhone formatted page instead. I build my sites in GoLive, so I'm not as good with code.

Help!
 
Some custom code and iWebkit

Code I use to redirect is quite simple, although requires php:
PHP:
<?php
// Powered by www.codynz.com

if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE)
{header("Location: /thelocationofthemobilewebsite/");}

else if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== FALSE)
{header("Location: /thelocationofthemobilewebsite/");}
?>

and visit http://www.iwebkit.net for the iPhone customised website templates.
 
...

Simpler option:

PHP:
<?php

// Screw licenses.  This is too trivial.  Use this code any way you want.

define('MOBILE_SITE_URL', 'http://example.com/m');
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE ||
   strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== FALSE) {
	
	header("Location: " . MOBILE_SITE_URL);	
}

?>
 
Even Simpler

Look ive made it even simpler:

PHP:
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== FALSE) {
header("Location: /locationofmobilesite/");    }
?>
 
I understand that I put my site address where it says to but what do I put where it says user agent?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.