views:

89

answers:

2

I am owning some websites, in php, java and html coded. I want them to be viewed comfortably using iphones. ie, the site has to first check whether the site is hit from a pc or mobile (iphone). If its from a mobile, it has to be redirected to another server which loads the mobile view. Some sites i've recently found of doing the same is orkut, facebook,etc. While logging in from a mobile, we are redirected to m.orkut.com from www.orkut.com, i've to do something similar to that.

+3  A: 

Check the user-agent*

$_SERVER["HTTP_USER_AGENT"]

and redirect

header("location: http://mobile.mysite.com");

where necessary.

* Note that the iPhone has many user-agents, and therefore checking the string itself for exact comparison isn't practical. Instead, look for strings like "iPhone" and "Mobile" to determine the liklihood that the current visitor is on an iPhone.

Jonathan Sampson
+2  A: 

Check the user agent. If it contains "MobileSafari" or "iPhone", its an iPhone. Other devices need a different check, of course. Google can be used to find the exact user agents, but be warned they change for each iPhone version.

PHP code to redirect:

header("Location: http://your-desired.site.com/");
chpwn
also `iPod` for iPod Touch
Anurag