好吧,我會盡量保持這種簡單和甜蜜。我正在使用我的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