[英]How to display localized time, based on a visitor's Ip address?
I get the ip address of the user by function. 我按功能获取用户的IP地址。
e.g
$ip_address = getIP();
Now I want display current localized time and date based on a visitor's Ip address using PHP. 现在我希望使用PHP根据访问者的IP地址显示当前的本地化时间和日期。 if it is possible than guide me How?
如果有可能比指导我怎么样?
Waiting for the Help and Thanks In advance. 等待帮助并提前致谢。
As pointed out in comments - this has been asked and answered 正如评论中指出的那样 - 已经提出并回答了这个问题
But one answer not included is to use a Javascript callback, or store tiem offset in a cookie from Javascript (or adjust times on display). 但是不包括的一个答案是使用Javascript回调,或者在Javascript中存储cookie中的tiem偏移量(或调整显示的时间)。
Example using a callback: 使用回调的示例:
Code: 码:
var d = new Date()
window.location.href = PageYouWant + '?offset=' + d.getTimezoneOffset();
(Vary according to your needs) (根据您的需要变化)
You can do a similar thing with cookies (if you don't have the cookie, send a holding page that creates the cookie and calls you back). 你可以用cookies做类似的事情(如果你没有cookie,发送一个创建cookie的召开页面并给你回电话)。
Keep the holding page blank and no-one will notice it - just looks like the page is loading. 保持页面空白,没有人会注意到 - 只是看起来页面正在加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.