dongxi0605 2017-03-02 00:19
浏览 61

使用Laravel使用php检测用户时区

I am trying to detect the user timezone and to display some content specific the time in that area.

For that purpose I am using jsTimezoneDetect to get the user timezone. After than i submit that timezone to PHP using AJAX and set a cookie with the user timezone.

PHP Code:

public function set() {
    $value = Input::get('timezone');
    Cookie::make(Config::get('variables.cookies.timezone'), $value, 30*24*60*60);
}

Javascript:

jQuery(document).ready(function () {
    var timezone = jstz.determine();
    $.post('timezone/set', {_token: $('meta[name="_token"]').attr('content'), timezone: timezone.name() }, function(data){

    });
});

Here i get some strange things:

1) If I get alert(timezone.name()), I see the user timezone, no matter the browser, but in the PHP Controller after I set the Cookie, Chrome does not display me that cookie.

2) It does not work, if I try to get the cookie like that:

Cookie::get('timezone');

3) It works only in FireFox and only like that:

$_COOKIE['timezone'];

And one global question. As a timezone i get Europe/Helsinki, but setting is not set in my Windows Datetime Settings neither in php.ini. Where does that come from ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数