【发布时间】:2017-02-17 00:20:49
【问题描述】:
我正在开发一个新产品/网站,主页(而不是子页面)应该对访问者关闭,直到网站启动。应该像这样从 URL 中读出发布日期:
website.com/some-subpage?launch=0421
在本例中,从 4 月 21 日 (21) 日 (04) 日起,访问者应该可以访问主页。
为此,我想这样做,如果有人访问“某些子页面”(或任何其他子页面,没关系),应该像这样设置 cookie:
- Cookie 名称:启动
- Cookie 值:0421
- Cookie 过期:在发布时,因此在本例中为 4 月 21 日
这是我目前所拥有的:
<?php
if ($_GET['launch'] != "null") {
date_default_timezone_set('Europe/Berlin');
$launchdate = $_GET['launch'];
$launchdatenew->format('*********'); // Here I probably need to convert the "0421" to a readable time, but I dont know how
// or probably using this version?
$launchdatenew = date_format(date_create_from_format('m d', $launchdate), '*********'); // Here I probably need to convert the "0421" to a readable time, but I dont know how
setcookie("Launch", $launchdate, $launchdatenew, "/"); // The Cookie-Name should be "Launch", the value "0421", and it should expire when the launch starts
} ?>
你能帮我完成这个吗?我不知道如何将“0421”转换为可以设置为 cookie 过期日期的新格式。不幸的是,我的 PHP 技能几乎为零。
非常感谢! 再见, 伊姆雷
【问题讨论】:
-
您是否遇到错误?什么不起作用?显而易见的事情是您信任的用户土地数据
$_GET['launch'];,然后也将其存储在用户土地中。 -
不,我还没有测试它,因为我确定它不会工作(我不知道如何将“0421”转换为可以设置为到期日期的新格式cookie。这不是问题,用户可以操纵它——他们不会。
-
他们会的。永远不要相信他们。
标签: php cookies time setcookie