Jump to content

Recommended Posts

My site looks less than flattering on a Pocket PC / Smartphone; so I want to alter the display based on whether the site is being viewed from a web browser on a computer (greater than 800x600 resolution) or whether it's being viewed by a smaller hand-held device.

My question is this: How do I go about determining this information?  Is there a PHP global I need to check? Or is there another generally accepted method for determining this?

Thanks,
Phil.
Ths simple answer is to create a style sheet for handheld devices.....

This is how some of my bigger sites css is declared.....

<link href="/global/css/screen/screen1.css" rel="stylesheet" type="text/css" media="screen">
<link href="/global/css/braille/braille.css" rel="stylesheet" type="text/css" media="braille">
<link href="/global/css/aural/aural.css" rel="stylesheet" type="text/css" media="aural">
<link href="/global/css/handheld/handheld1.css" rel="stylesheet" type="text/css" media="handheld">
<link href="/global/css/print/print1.css" rel="stylesheet" type="text/css" media="print">
<link href="/global/css/tv/tv1.css" rel="stylesheet" type="text/css" media="tv">

There is a style sheet there for every type of device that cn view your site.  You just need to add the media attribute to let the client know which sheet it should use.
Thanks, this is great information.

In my current application however, I use CSS for simple text formatting (colors, fonts, etc) and a template engine (Smarty) for layout.  My intention was to create a separate template for handheld devices; when a visitor comes I check which category they fall into and direct output to the appropriate template.

Any further advice on how I would check in this instance?
You can get the user agent from $_SERVER['HTTP_USER_AGENT'] - this contains a string relating to the browser configuration, I believe from that you can extract the browser type and operating system.

EDIT: Try looking up the get_browser() function here: [url=http://www.phpfreaks.com/phpmanual/page/function.get-browser.html]http://www.phpfreaks.com/phpmanual/page/function.get-browser.html[/url]
All these are well and good BUT....

You can save yourself a lot of work and hassel by producing a site has semantic markupand then simply use the css methods I described earlier.

Not done much with smarty templates but if you can edit them yourself and create a layout that has no in-line styling (such has height width padding etc.) and simply give elements a class or id then this would be a site that would (could) look good in all clients and be 3000000 times easier to manage......
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.