This is very simple, even for people who don't know PHP. Our site uses this script to auto-redirect iPhone users to our specially designed iPhone page. Here is our PHP:
<?php
$browser = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if ($browser === true) {
{ echo 'Code You Want To Execute'; }
?>
So lets disect this,
$browser = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone")
"$_SERVER['HTTP_USER_AGENT']" is a function built into PHP, to get various amounts of information from the users browser. You can read more about this function here.
Next, using another built in function of PHP stripos, we can search for a string inside our $browser. If stripos finds "iPhone" in $browser, it will let us run the code in side the if statement
if ($browser === true) {
{ echo 'Code You Want To Execute'; }
So what can you put in the if statement?, you can put a redirect, a different stylesheet link or just post a special message to iPhone users. I hope this basic tutorial helps you with your iPhone Application!
Download This Script