tags:

views:

68

answers:

4

Hello everyone

I wonder if there is a way to recognize the visit from user's iphone and automatically adjust web page to fit iPhone screen size?

+1  A: 

Yes, there is a way. User-Agent HTTP header is your friend.

Anton Gogolev
+1  A: 
<?php
$isIphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if ($isIphone == true)  { echo 'Code You Want To Execute'; }
?>
henchman
+1  A: 

I'd say that rather than basing it on the UA, often a screen size query is better. I have used this before in my head.

<!--[if !IE]>-->
<link type="text/css" rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iPhone.css">
<!--<![endif]-->
Rich Bradshaw
A: 

You can do User-Agent detection and make changes based on seeing the "iPhone" or "iPod" string, but you can also use a meta tag that is specifically for this purpose.

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"> 

Here's another good resource for information on building an iPhone-ready website.

Kevin Gorski