472,779 Members | 2,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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 5086
$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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.