I want an opt-in beta site, that users can also opt-out of,
On doma开发者_开发技巧in.com
there will be a link to allow users to goto beta.domain.com
I want it so that every time they visit they are automatically redirected to beta.domain.com
but there they can also unset the cookie to just goto domain.com
I have tried some stuff but just ended up in a recursive loop :P
Any ideas?
When entering beta.domain.com
create a cookie on the domain level:
setcookie("BetaUser", 1, time () + (60*60*24*30), '/', '.domain.com');
Now when a user enters your page and you're on domain.com
(see $_SERVER) redirect to beta.domain.com
.
When the user wants to opt-out of your beta, provide a link to a opt-out page that unsets the cookie and redirects back to domain.com
.
link:
<a href="/?switch-to-beta.php">switch to beta</a>
switch-to-beta.php code:
setcookie('use_beta', '1', time()+3600*24*365*10, '/', 'domain.com');
header('Location: http://beta.domain.com/');
exit;
At start of index file on domain.com
if(isset($_COOKIE['use_beta']) && $_COOKIE['use_beta']){
header('Location: http://beta.domain.com/');
exit;
}
link to stop redirection on beta.domain.com
<a href="http://domain.com/switch-to-stable.php">switch to beta</a>
switch-to-stable.php code:
setcookie('use_beta', '0', time()-10000, '/', 'domain.com');
header('Location: http://domain.com/');
exit;
精彩评论