【问题标题】:Session cookie in different browsers with a wrong client time客户端时间错误的不同浏览器中的会话 cookie
【发布时间】:2014-01-22 21:35:31
【问题描述】:

cookie 有问题。我有一个电池不好的 ARM 设备 - 所以这个设备上的时间可能是错误的 - 它可能在未来或过去。 Lighttpd 在设备上工作,并且有一个在 CodeIgniter 框架 (php) 上编写的应用程序。为了保存自动化,我使用标准系统库 Sessions 和 Cookie 助手。 cookie 的有效期为 2 小时。这是我的问题: 当设备在未来超过 2 小时时,客户端上的 Chrome 和 Firefox 无法自动执行(他们认为 cookie 已经过期并且无法保存会话),但 Opera 可以并且运行良好。 你知道如何让它独立于服务器和客户端的时间设置工作吗?

【问题讨论】:

  • 你的服务器运行的是什么操作系统?
  • 它是 Angstrom 嵌入式 linux。

标签: php codeigniter session cookies


【解决方案1】:

听起来您需要将服务器配置为使用网络时间协议。

众所周知,Linux 机器无法自行跟踪时间,因此为了使您的时间保持同步,建议从 NTP 服务器同步时间。

虽然我对 Angstrom 不是特别熟悉,但我相信以下说明应该有效:

在您的服务器上安装 NTP(如果您尚未安装):

opkg update
opkg list|grep ntp
opkg install ntp

然后您需要配置您的 NTP 配置文件(位于 /etc/ntp.conf)以使用 NTP 服务器。

找到一个相关的服务器,我一般用http://www.pool.ntp.org/en/,然后选择右边的时区,你会得到很多可以使用的服务器。

编辑您的 /etc/ntp.conf 文件并添加以server 为前缀的服务器地址,以便您的配置文件看起来类似于:

# This is the most basic ntp configuration file
# The driftfile must remain in a place specific to this
# machine - it records the machine specific clock error

driftfile /etc/ntp.drift
logfile /var/log/ntpd.log

# BELOW IS WHERE YOU ADD YOUR SERVER RECORDS #

# NTP Servers for Ireland from www.pool.ntp.org
server server.address.1
server server.address.2
server server.address.3
server server.address.4

# Using local hardware clock as fallback
# Disable this when using ntpd -q -g -x as ntpdate or it will sync to itself
# server 127.127.1.0 
# fudge 127.127.1.0 stratum 14

# Defining a default security setting
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

启动您的 NTP 服务,您应该与世界其他地方同步...

systemctl enable ntpdate.service
systemctl enable ntpd.service

【讨论】:

  • 感谢您的建议,但有一个小问题:它是本地网络设备,因此没有互联网连接。
  • 问题已解决。解决方案在我的回答中。感谢您的参与。
【解决方案2】:

我为解决这个问题所做的工作: 将 cookie 的过期属性设置为零,但在服务器端保留过期检查。 自动化运行良好,cookie 不会浪费浏览器的存储空间和会话在我在应用程序中设置的时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 2014-04-04
    相关资源
    最近更新 更多