Though not typically recommended, user agent detection can be useful for presentations formatted for the iPhone/iPod touch specifically. This PHP tutorial can be used to detect the user agent of the iPhone browser, allowing you to forward a visitor to the iPhone version of your website.
Below is the PHP:
< ?php
$browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if ($browser == true) { echo 'Code You Want To Execute'; }
?>
Lets dissect this,
$browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone")
“$_SERVER['HTTP_USER_AGENT']” is a function built into PHP, which gets information about the users browser. You can read more about this function here.
Next, using strpos, another built in function of PHP, we search for a string inside our $browser variable. If strpos 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'; }
From here, you may want to extend the if statement to redirect the user to your iPhone microsite, use a different stylesheet or just post a special message to iPhone users. It’s up to you.
We hope this basic tutorial helps with your iPhone microsite development. You may also consider using CSS to detect iPhone visitors as other phones using MobileSafari could be accidentally detected using this method. We’ll cover this topic in another tutorial. As always, let us know what you think.


Hi! This is an incredibly basic question but I’m new to web coding and PHP. I’m already using a PHP script for my contact page to forward on simple email messages but this is activated by the users interaction. Just wondering how this PHP file is initiated upon accessing the website index.html? Thanks.
You need to rename the index.html file with a .php extension if you want the PHP code contained inside to execute in a browser.
I came here looking for something else but I wanna help you or somebody who need it in near future.
You can modify the directives for handle html like php file with .htaccess (just open it as text file)
For web servers using PHP as apache module:
Add this line:
AddType application/x-httpd-php .html .htm
For web servers running PHP as CGI:
AddHandler application/x-httpd-php .html .htm
Good luck.