Page 1 of 1

iPhone detection and redirection with php

Posted: Tue Jun 22, 2010 1:28 am
by abbyeagle
Hi, I want to redirect a visitor using an iphone to a separate iphone subdomain. I have added the following code to the top of a webpage but the page then does not load at all. I put the code hard top left of the page. Is there something else that i need to do?

<?php

//setting the variables
$ipod = stripos($_SERVER['HTTP_USER_AGENT'],”iPod”);
$iphone = stripos($_SERVER['HTTP_USER_AGENT'],”iPhone”);

//detecting device
if ($ipod == true || $iphone == true){
header( ‘Location: http://www.m.abbyeagle.com/’ ) ;
} else {
header( ‘Location: http://www.abbyeagle.com/styles/index.php/’ ) ;
}
?>

Re: iPhone detection and redirection with php

Posted: Tue Jun 22, 2010 12:16 pm
by Jade
Are you getting an error message? Perhaps you're stuck in an endless loop somehow?

Re: iPhone detection and redirection with php

Posted: Tue Jun 22, 2010 12:21 pm
by AbraCadaver
This will need to be at the very top of the page before <html... or anything else. Also, you need an exit; after each of your header() calls.