I created a non-Flash page for iPhone/iPod users and placed a text link on the Flash page for iPhone/iPad users to go to my site. After researching, I found the following sniffer code at http://davidwalsh.name/detect-iphone to insert into the html so users can get to the appropriate homepage more quickly:
The JavaScript
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
if (document.cookie.indexOf("iphone_redirect=false") == -1) window.location = "http://m.espn.go.com/wireless/?iphone&i=COMR";
}
Copy this code to the clipboard
1if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
2 if (document.cookie.indexOf("iphone_redirect=false") == -1) window.location = "http://m.espn.go.com/wireless/?iphone&i=COMR";
3}
The code itself is short and sweet. I, however, would prefer using the server-side method of user agent checking.
The PHP
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
{
header('Location: http://yoursite.com/iphone');
exit();
}
Copy this code to the clipboard
1if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
2{
3 header('Location: http://yoursite.com/iphone');
4 exit();
I'm assuming I can't add it to a page via HTML snippet and I have to go to the root HTML, right? If so, can I just insert it anywhere? Thanks for your help! By the way, GREAT GREAT site; I'm almost ready to launch!!!!!
Jamie




