我想让我的网站的新版本,并要求用户尝试它,但我想要相同的url
这是最干净的方法吗?
// code executes if user asks to make the new version the default.
setcookie("newversion", "true", mktime(0,0,0,12,31,2011));
这是/index.php
if($_COOKIE['newversion'] == "true") {
/**
* load the new version of the site.
*
**/
exit();
} else {
/**
* load the older version of the site.
*
**/
}
我没有找到任何这类的教程或问题,所以请帮助。
这正是youtube实现HTML5视频的方式(通过PREF
cookie)。由于您通常只想更改站点的一部分,因此代码可能看起来像:
$prefs = array('version'=>'1', $html5=false);
$prefs = array_merge($prefs, parsePrefs($_COOKIE['PREFS']));
if ($prefs['version'] == '1') {
old_header();
} else if ($prefs['version'] == '2') {
new_header();
}
或者,您当然可以两个最初不同的控制器路径(如在您的示例中),最终调用相同的辅助函数。