好吧,我会尽量保持这种简单和甜蜜。我正在使用我的wesbsite,并且当用户第一次加载站点时,它当前加载了一个启动页面。这是我想要的行为。使用PHP和Javascript重定向并设置Cookie
- 如果用户以前从未去过网站,则重定向到splash页面。
- 如果用户以前曾经访问过该网站,并且不想看到这个splash不重定向。
- 如果用户喜欢飞溅并希望在新会话中看到,请显示启动页面。
那些基本上与我一起工作的场景,不能再真正想到,在过去的几个小时里一直在试图破解一些东西,没有运气。
的index.php
<?php
setcookie("visit", "true", mktime (0, 0, 0, 12, 31, 2014), "/"); // delete cookie on 31DEC14
$cookie_splash = $_COOKIE['splash'];
$cookie_visit = $_COOKIE['visit'];
$cookie_visit_now = $_COOKIE['visit_now'];
do {
if ($cookie_splash == '' && $cookie_visit == '' && $cookie_visit_now == '') {
/*
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/splash.php'";
echo "</script>";
*/
header('Location: splash.php');
}
if ($cookie_splash == 'false' && $cookie_visit_now == 'true') {
break;
}
if ($cookie_splash == 'true' && $cookie_visit_now == 'false') {
/*
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/splash.php'";
echo "</script>";
*/
header('Location: splash.php');
}
if ($cookie_splash == 'true' && $cookie_visit == 'true' && $cookie_visit_now == "false") {
/*
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/splash.php'";
echo "</script>";
*/
header('Location: splash.php');
}
if ($cookie_splash == 'true' && $cookie_visit == 'true' && $cookie_visit_now == 'true') {
break;
}
}
while (0);
?>
splash.php
<p>
<form name="tosplashornottosplash" action="scripts/splash-process.php" method="post" onSubmit="return valForm()">
Splash pages are stupid.
<input type="radio" name="splash" id="splash_false" value="false" /> No
<input type="radio" name="splash" id="splash_true" value="true" /> Yes
<input type="submit" name="splashSubmit" onClick="return valForm(tosplashornottosplash)" value="Enter" />
</form>
</p>
防溅process.php
<?php
setcookie("visit", "true", mktime (0, 0, 0, 12, 31, 2014), "/"); // delete cookie on 31DEC14
setcookie("visit_now", "true", NULL, '/'); // cookie should expire/delete at end of session.
$splashvar = $_POST["splash"];
if ($splashvar == "false") {
// create cookie - splash 1
setcookie("splash", "true", time()+3600, '/'); // expires in one hour
}
else {
// create cookie - splash 0
setcookie("splash", "false", time()+3600, '/'); // expires in one hour
}
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/index.php'";
echo "</script>";
?>
转到chrisr jones.com看看我在说什么。
怎么回事?需要修改哪些内容?请多一点信息。 – 2013-02-09 02:37:57