ki Posted November 28, 2007 Share Posted November 28, 2007 Does anyone know how to tell if your using an iPhone to view a site yet?, cause I wanna make a totally different site then Quote Link to comment Share on other sites More sharing options...
Silverado_NL Posted November 28, 2007 Share Posted November 28, 2007 php is a server-sided scripting language and doesnt have anything to do with the browsers that visit's the page, you would better be off asking on a javascript forum. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 yes you can with js Quote Link to comment Share on other sites More sharing options...
centerwork Posted November 28, 2007 Share Posted November 28, 2007 Can't that also be set up with a CSS Syle sheet? Quote Link to comment Share on other sites More sharing options...
Silverado_NL Posted November 28, 2007 Share Posted November 28, 2007 hmm i think javascript would reconize the iphone with its resolution or would lookup the browser name or engine or something. and i dont think css would be able to do that. afterall its a stylesheet, not a browser plugin. you might be able to create a stylesheet that would be compatible with the iphone, but then again how would your script know what stylesheet to use? Quote Link to comment Share on other sites More sharing options...
helraizer Posted November 28, 2007 Share Posted November 28, 2007 and i dont think css would be able to do that. afterall its a stylesheet, not a browser plugin. The CSS won't detect it but you can use a different page with <link media=""> The different medias make it more viewable/compatible for different systems. Quote Link to comment Share on other sites More sharing options...
deadimp Posted November 28, 2007 Share Posted November 28, 2007 Getting the user agent string from the client (browser), like Silverado_NL said, would be your best bet. You could use either javascript or php ($_SERVER['USER_AGENT']) for that. Quote Link to comment Share on other sites More sharing options...
s0c0 Posted November 28, 2007 Share Posted November 28, 2007 Using javascript you can in fact dynamically set what css file to use. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 28, 2007 Share Posted November 28, 2007 I'll admit I'm not up to speed on developing sites for hand-helds or other small displays, but here's my advice. You can be fancy and detect the browser via Javascript or PHP (via $_SERVER) as suggested, but some people will have Javascript turned off. Others might have their browser configured to tell sites it is a different browser (which would render PHP's ability to correctly identify the user agent in $_SERVER useless). So no matter what automatic detection you decide to use, it may fail, and you should still provide a 'Reload this page for a small display or hand-held device' link. No matter how you determine to display your alternate .css (automatic detection or user action), set a flag in $_SESSION that tells the site to use the alternate .css. Do it in $_SESSION because you can still use sessions even when cookies are disabled. Additionally, set a permanent cookie in the user's browser that says to use the alternate style sheet. On your visitor's next visit to the page, look for the permanent cookie and if it's present use the alternate stylesheet. If it's not present, revert back to your automatic or user specified action. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.