背景。
domain.com =一个即将进入测试的网站LAUNCH.domain.com =启动页面和文本字段,有人可以在
中输入邀请码auth_check.php -哪个launch.domain.com的帖子提交
如果splash页面上输入的数据与auth_checkphp匹配,那么用户将被重定向到domain.com
如果用户从未访问过domain.com,他们将被发送到launch.domain.com
这个问题。
当我输入代码到launch.domain.com时,它会把我送到domain.com,所以它工作得很好。
但是cookie没有被存储。在我关闭浏览器并重新打开它以返回domain.com之后,我被发送到launch.domain.com
是我的代码。
auth_check.php
<?php
$invite_code = "getaccess"; ----that is the code that must be entered in to form
$site_url = "http://www.domain.com"; --- main domain....
$thank_you_url = "http://www.domain.com/register.php"; ---- page they get sent to after entering the correct code
if(isset($_POST['invite_code']) && $_POST['invite_code'] == $invite_code) {
setcookie("can_see","true"); ----- invite code is the name of the text field
header("Location: ".$thank_you_url);
exit;
}
header("Location: ".$site_url);
exit;
?>
index . php
<?php
$register_url = "http://www.launch.domain.com";
if(!$_COOKIE['can_see']) {
header("Location: ".$register_url);
exit;
}
?>
表单工作正常。所以我把它删掉
我刚刚测试了这个最后一次,它在internet explorer中工作良好- cookie设置在chrome和IE中,但它不存储
任何输入都会很棒!!
谢谢
cookie可能被存储,但由于地址不同- "domain.com" vs "launch.domain.com" -它没有被发送回服务器。
你能做的是给setcookie
添加一个参数,这样cookie对整个域和任何子域都有效:
setcookie("can_see", "true", 0, "/", ".domain.com");
将cookie的名称设置为"can_see",值设置为"true",过期日期设置为"每当浏览器关闭时"(即会话cookie), cookie到域根的路径,cookie的域设置为"。domain.com"(带前段)。这将使所有子域(www, launch, ftp, mail,等等)都可以读取cookie
参见setcookie的文档,但基本上,如果你没有给出过期日期,它是一个会话cookie,当浏览器关闭时将被清除。
在您的原始答案中,您说子域和域可能是一个问题,所以我只是将启动子域的内容移动到domain.com/launch添加了您的代码行,它可以工作。
我将0改为time()+(60*60*24*365)。
似乎工作得很好。
谢谢老兄。