 |
 |
Can scripts (Perl, PHP) detect media type for handheld?
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
I'd like to offer a "handheld"-friendlier verion of my navigation system on our web site.
Right now that is generated via a series of php include. Logically speaking it would make the most sense to detect the handheld and branch to a different include file... but its not clear to me that a cgi script can detect this value... ie. I'm wondering if its only "client-side" and thus I must ship over both versions of the nav bar, wrapped in differing css tags, and the browser will choose which to display... which seems like an awful waste of bandwidth to me (especially when mobile speeds are usually slower to begin with).
Is there a way to detect this on the server?
Thanks,
Mike
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status:
Offline
|
|
You need to look at the http headers for that information. The CGI specification was originally devised to deliver exactly that to scripts. The actual list of what is available and how it is available depends on your language of choice (most make almost everything available). For php see:
http://us4.php.net/manual/en/languag...predefined.php
The difficulty is that the devices probably can support a number of different formats, so you might have to use something akin to browser detection (usually a bad idea, because it is really prone to breaking, since it depends on a simple string whose format was never standardized).
The best solution would be to offer a WAP version of the site.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
You can try using User-Agent sniffing, but a fair number of handheld user-agents either don't send one at all or lie about it to get around User-Agent sniffers.
There are also CSS media types for use with handhelds (I believe media="handheld" is what you're looking for) that you may want to investigate. You could use this to serve exactly the same content but present it in a way that's friendlier to handhelds. It's probably easier in the long run to do it this way.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
Ya, the CSS media type handlheld is the straightforward way to do it, but I already offer my users 2 types of navigation (generated by 2 different scripts, keyed off of a cookie value).. thought the most obvious solution was to key of another value to choose a 3rd possible nav-generation-script.
The frustration I have with the css type tho is that its all well and dandy to wrap things in
@media "handheld" { display:none; }
but now I'm shipping 2 versions of the same content over the wire to EVERYONE... which seems an awful waste of bandwidth (yes I know its old fashioned to care), and egregious to wireless destinations that pay by the byte, and/or on a slow connection. It seems to me the whole idea should be not to ship them the content, not ship it all the way there and then let them decide not to display it (which is my understanding of how css works).
In an ideal world each navigation item could just be wrapped in a class tag and displayed differently, but the differences I envisioned for handheld would be completely different html, not something that is just a change of font size, color, block/inline, etc.
As far as I can tell that leaves me only the choice of keying off of browser type, which I really don't want to do. The only nice trick I've noticed is keying off of 240x320 in the browser id string.
I noticed that even on my new Pocket PC, one browser uses handheld material, the other just uses screen.
Cheers,
Mike
PS. I'm venting at the standards not at you guys..  appreciate the replies... I was hoping I was missing a nice magic solution.
(Last edited by Zim; Jan 13, 2005 at 04:04 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
FWIW, I decided to go the hack route
PHP:
Code:
$ua = $_SERVER['HTTP_USER_AGENT'];
if (((substr_count("$ua","240x320") + substr_count("$ua","PDA")) > 0)) {
include "nav_handheld.php";
else {
include "nav.php";
}
Perl:
Code:
$ua = $ENV{'HTTP_USER_AGENT'};
if ( ($ua =~ /240x320/) || ($ua =~ /PDA/)) {
$navstyle = "handheld";
}
In case this might someone else later.
Mike
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|