By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Parsing HTTP_ACCEPT to detect mobile clients

P: n/a
Hi,

I want to configure my home page to redirect clients using WAP or i-mode
browsers. I'm sure this problem must have been tackled by lots of people
already, but I couldn't find any decent material on the subject. This is
what I'm using at the moment:

= = = = = = = = = = = = = = = = = = = = = = = = = = = = =
/* Redirect non-standard user agents */

header("Vary: User-Agent,Accept");

$acc = $_SERVER['HTTP_ACCEPT'];
$accw = strpos($acc, "text/vnd.wap.wml");
$acch = strpos($acc, "text/html");
$accw = ($accw !== false) ? $accw : 9999999;
$acch = ($acch !== false) ? $acch : 9999999;

if ($accw < $acch) {
header("HTTP/1.1 302 Found");
header("Location: http://www.mywebsite.com/wap/");
exit;
}

if (substr($HTTP_USER_AGENT,0,7) == "DoCoMo/") {
header("HTTP/1.1 302 Found");
header("Location: http://www.mywebsite.com/imode/");
exit;
}
= = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Basically this script treats any user agent that identifies itself with a
string starting "DoCoMo/" as an i-mode browser, and redirects to the WML
pages when the string "text/vnd.wap.wml" appears closer to the beginning of
the browser's Accept header than the string "text/html".

This is flawed for (at least) 2 reasons:

1. There are probably other cHTML browsers that would be happier with the
i-mode content, but I don't know how to identify them.

2. The Accept header parsing doesn't recognize the "q=" syntax of Accept
fields.

Before I start re-inventing the wheel, can anyone point me in the direction
of a script that does this sort of thing properly?

Thanks in advance,

Phil

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
$acc = $_SERVER['HTTP_ACCEPT'];
$accw = strpos($acc, "text/vnd.wap.wml");


Be careful. Opera for desktop supports WAP!
Maybe you'll find this useful: http://wurfl.sourceforge.net/
--
* html {redirect-to: url(http://browsehappy.pl);}
Jul 17 '05 #2

P: n/a
porneL wrote:
$acc = $_SERVER['HTTP_ACCEPT'];
$accw = strpos($acc, "text/vnd.wap.wml");
Be careful. Opera for desktop supports WAP!


It doesn't mention this when sending out Accept headers, fortunately.
Maybe you'll find this useful: http://wurfl.sourceforge.net/


Surely this *can't* be the right way of doing things? I'd prefer to work
with the information provided by the UA itself rather than maintain a list
of every browser in existence.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.