473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Parsing HTTP_ACCEPT to detect mobile clients

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
2 5118
$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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: erickrefener | last post by:
Hi, I use PHP (and PHP socket functions) to exchange very short XML documents between two Flash clients like this : <MESSAGE id="myid" text="mytext" /> I don't parse the XML document within PHP...
0
by: Stephan | last post by:
Hello to all, I'm looking into providing mobile access to a web based administrative application currently running on .Net with MS SQL. The current architecture only supports the latest Internet...
10
by: Ben Xia | last post by:
Is there some way can detect MAC address with PHP? any help will be appreciate. Ben
3
by: Sara | last post by:
HI, I want to code a program to detect GSM mobile (any kind) which connected through serial port to computer and then be able to send SMS through this mobile phone to other mobile phones, could...
4
by: Sara | last post by:
Hi I want to code a program which could send SMS through web page to mobile phone, but because there is no Service here such as SMPP , therefore I have GSM mobile phone which connected directly to...
1
by: charlesvc | last post by:
Hallo I am working on web design on mobile. So i came to know for webpage in html or xhtml needs to be parsed to show on mobile So my doubt is the parsing will give only tags text...
0
by: =?Utf-8?B?Q2xhcmU=?= | last post by:
Hi groups, VS2005 + Mobile SDK 6 work well on my PC, but after installing platform builder 5.0, VS2005 shows “XML parsing error” when open *.sln. We reinstall VS2005, Mobile SDK and platform...
1
nine72
by: nine72 | last post by:
Ok, I am at a complete loss on this and have finally come to the XML Parsing Gods (and perhaps a PHP minor deity) for guidance… I will try my best to describe what I have going on… 1) I have 15...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.