iPhone detection and redirection with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abbyeagle
Forum Newbie
Posts: 1
Joined: Tue Jun 22, 2010 1:15 am
Location: Gold Coast Australia

iPhone detection and redirection with php

Post 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/’ ) ;
}
?>
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: iPhone detection and redirection with php

Post by Jade »

Are you getting an error message? Perhaps you're stuck in an endless loop somehow?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: iPhone detection and redirection with php

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply