Tip: How to detect with PHP if iPhone visits your site
Saturday, January 30, 2010 2:17Currently I’m developing some websites which “can be visited from iPhone” [the customer say that], the big thing is: there are some javascripts functions to detect it but when you use it with jQuery this “lock” the effects.
The solution is so easy, you just need to use this PHP script:
PHP<5.3.0
if (ereg('iPhone',$_SERVER['HTTP_USER_AGENT']))
{
header("Location:/iphone.html");
}
PHP>=5.3.0
if (preg_match("/iPhone/",$_SERVER['HTTP_USER_AGENT']))
{
header("Location:iPhone.php");
}
Take Care: Is Important if you have PHP bigger than 5.3.0 you need to use preg_match instead of ereg, becuase ereg is DEPRECATED in PHP 5.3.0 and will be delete in PHP 6.0.0
The function is so easy, because it detect if appears the “iPhone” word in the string HTTP_USER_AGENT. Anyway, this is easily handly in Firefox just need to change the User Agent in about:config writting:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; es-es) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16

You need to restart firefox when you do this
[With the UserAgent changed even my blog load in iPhone Format]

[remember to put back the configuration when you finish to play with it (Firefox/x.x.x) [x.x.x = your version...]
]
You can see here the example [just add a x to .php to see the source code]
And here the screenshoot from the iPhone
![IMG_0053[1]](http://bredebs.net/wp-content/uploads/2010/01/IMG_00531-e1264828465721.png)
Cheers, and I hope this could help you [soon i will publish it in ASP.net]


