2

为手机开发网站是一个完全不同的世界吗?

我如何检测页面是从计算机还是从手机访问的?

我问这个是因为我看到如下代码:

if (isset($_SERVER['HTTP_ACCEPT']) &&
(strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml')!==FALSE)
&& (strpos($_SERVER['HTTP_ACCEPT'],'text ml') === FALSE 
||
(strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml') <
strpos($_SERVER['HTTP_ACCEPT'],'text ml'))

)) { //cellphone

   readfile('index.wml');

} else readfile('index.htm');

如何将代码移植到 C# 中?

4

5 回答 5

3

在 php 中,您通常会检查$_SERVER['HTTP_USER_AGENT']标头以识别 Web 请求源自的 Web 浏览器。

为移动浏览器开发网站并不是一个完全不同的世界。但是,您必须牢记以下限制:

  • 屏幕尺寸:不仅您的屏幕空间更小,而且不同移动设备之间的尺寸和方向也有很大差异。

  • Flash 支持:大多数移动浏览器不支持 Flash。

  • JavaScript 支持:在移动浏览器上,JavaScript 比 Flash 更受支持,尤其是在现代手机和 PDA 中。

  • 渲染性能:复杂页面需要更长的时间才能在移动浏览器中渲染。一般来说,如果您决定使用 JavaScript,那么通过 JavaScript 对 DOM 的操作应该是最少的。

  • 移动带宽:请记住尽可能压缩图像,并缩小所有 HTML、CSS 和 JavaScript。

于 2009-12-31T03:13:15.017 回答
2

要检测手机并了解其功能,您可以使用WURFL库。

于 2009-12-31T03:15:15.480 回答
0

You are going to want to take a look at this MSDN article on Getting Mobile: Using WML and WAP to Display Web Sites on Mobile Devices. By designing WML, the mobile phone knows to use the low-res version.

This page here on Detecting Mobile Devices using ASP.NET and C# shows you how to do it with classes ported from PHP. The API in that link can detect iPhones, Androids, Blackberries, Symbion, etc.

WML decks are stored on an ordinary web server trivially configured to serve the text/vnd.wap.wml MIME type in addition to plain HTML and variants. The WML cards when requested by a device are accessed by a bridge WAP gateway, which sits between mobile devices and the World Wide Web, passing pages from one to the other much like a proxy. The gateways send the WML pages on in a form suitable for mobile device reception (WAP Binary XML). This process is hidden from the phone, so it may access the page in the same way as a browser accesses HTML, using a URL (for example, http://example.com/foo.wml). (Provided the mobile phone operator has not specifically locked the phone to prevent access of user-specified URLs.)

Wikipedia Source

于 2009-12-31T03:43:46.250 回答
0

user198729 is asking how to do this in C#
The $_SERVER in PHP e.g $_SERVER['HTTP_ACCEPT'] is performed by Request.Headers in c#
e.g

Request.Headers["HTTP_ACCEPT"]
于 2011-07-13T03:18:39.450 回答
0

您可以解析用户代理字符串(很容易伪造),也可以使用媒体查询来检查诸如最小的最大视口大小之类的东西。

于 2009-12-31T03:15:09.893 回答