您可以从请求变量决定时区? [英] Can You Determine Timezone from Request Variables?

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

问题描述

有没有办法做你的时区偏移在服务器端,通过阅读一些通过HTTP请求,而不是发送给所有的客户端,并让它处理呢?

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?

推荐答案

这是比较复杂的,但我不得不求助于此方案之前,由于计算机和用户配置文件设置有时不符合您的访问者的preferences。例如,英国游客临时从澳大利亚的服务器访问你的网站。

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. 使用地理定位服务(如MaxMind.com)所建议的@balabaster,获取区域匹配的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来获取时区偏移量为表单提交的一部分/重定向。这是浏览器的电流偏移,但是的不一定访问者的preferred区的使用这个值作为默认。存储在另一个会话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天全站免登陆