你能从请求变量中确定时区吗? [英] Can You Determine Timezone from Request Variables?

查看:27
本文介绍了你能从请求变量中确定时区吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在服务器端进行时区偏移,通过 http 读取请求中的内容,而不是将所有内容发送到客户端并让它处理它?<​​/p>

Is there a way to do your timezone offsets on the server side, by reading something in the request over http, instead of sending everything to the client and letting it deal with it?

推荐答案

这更复杂,但我之前不得不求助于这种情况,因为机器和用户配置文件设置有时与访问者的偏好不匹配.例如,一位英国访问者从澳大利亚服务器临时访问您的网站.

This is more complicated but I've had to resort to this scenario before because machine and user profile settings sometimes don't match your visitor's preferences. For example, a UK visitor accessing your site temporarily from an Australian server.

  1. 使用@balabaster 建议的地理定位服务(例如 MaxMind.com)来获取与其 IP 匹配的区域(Global.Session_Start 是最好的).这对本地 ISP 来说是一个很好的匹配,但对 AOL 来说不是那么好.将此偏移量存储在会话 cookie 中.

  1. Use a geolocation service (e.g MaxMind.com) as suggested by @balabaster, to get the zone matching their IP (Global.Session_Start is best). This is a good match for local ISPs, but not so good for AOL. Store the offset from this in a session cookie.

或者在用户进入网站时使用 JavaScript 获取时区偏移量,作为表单提交/重定向的一部分.这是浏览器的当前偏移量,但不一定是访问者的首选区域.将此值用作默认值;存储在另一个会话 cookie 中.

Or use JavaScript to get the time zone offset as part of a form submission/redirect when the user enters the site. This is the browser's current offset, but not necessarily the visitor's preferred zone. Use this value as a default; store in another session cookie.


<script type="text/javascript" language="JavaScript">
var offset = new Date();
document.write('<input type="hidden" id="clientTzOffset" name="clientTzOffset" value="' + offset.getTimezoneOffset() + '"/>');
</script>

  • 允许访问者通过持久性 cookie(对于匿名用户)和他们帐户配置文件中的字段(如果经过身份验证)更新区域.

  • Allow the visitor to update the zone via a persistent cookie (for anonymous users) and a field in their account profile (if authenticated).

    来自的持久值 #3 会覆盖会话值.您还可以为经过身份验证的用户存储相同的持久性 cookie,以便在他们登录之前显示时间.

    The persistent value #3 from overrides the session values. You can also store the same persistent cookie for authenticated users for displaying times before they login.

    这篇关于你能从请求变量中确定时区吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆