正在添加过期日期上的远期日期


Adding far future date on expire date

我们可以通过将其放在.htaccess 上来操纵过期日期

ExpiresDefault "access plus 10 years"

我们希望在PHP文件中对此进行操作。在搜索类似的东西时。我遇到了:

$offset = 60 * 60;
$expire = 'expires: ' . gmdate ('D, d M Y H:i:s', time() + $offset) . ' GMT';
header ($expire);

但这只会给我们的到期日增加时间。对我们来说;我们希望今年有所改变。在php中有办法做到这一点吗?

您可以这样做:

$expire = 'Expires: ' . gmdate('D, d M Y H:i:s', strtotime('+10 years')) . ' GMT';
header($expire);

我使用strtotime创建当前时间+10年的时间戳。

你做得对。只需在几秒钟内将偏移量增加到10年。

为了将到期日期提前一年设置,您需要更大的$offset,current仅为小时(每分钟60秒*60分钟)。

    $offset = 365*24*60*60;