0

所以我对整个 Javascript / PHP 有点陌生。使用这两种语言进行编码确实非常有趣。现在,如果用户访问 chrisrjones.com,他们将被重定向到 chrisrjones.com/splash.php。有两个单选按钮询问用户是否喜欢启动页面。根据用户的选择,cookie 值设置为 true 或 false。一旦用户单击“进入”按钮,还会创建另一个名为“访问”的 cookie。

如果您的用户选择“是”,则启动页面是愚蠢的,他们会进入站点,但是如果在浏览器中关闭窗口/选项卡,则在重新加载站点时会显示启动页面。

如果用户选择“NO”启动页面是愚蠢的,他们根本无法进入该站点。

有没有办法让用户在点击任一按钮后进入网站?(一定有办法)

还有一种方法可以记住用户是否选择“是”而不是重定向它们。

index.php文件如下所示

<?php
$cookie_splash = $_COOKIE['nosplash'];
$cookie_visit = $_COOKIE['visit'];

if ($cookie_splash == "false" || $cookie_splash == "" && $cookie_visit == "") {
    echo "<script type = text/javascript>";
    echo "window.location = 'http://chrisrjones.com/splash.php'";
    echo "</script>";
}

if ($cookie_splash == "false" && $cookie_visit == "true") {
    echo "<script type = text/javascript>";
    echo "window.location = 'http://chrisrjones.com/index.php'";
    echo "</script>";

}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>chrisRjones.com</title>
<!-- default - stylesheets at the bottom override styles at the top -->
<link rel="stylesheet" type="text/css" media="screen" href="stylesheet.css" />

<!-- favicon -->
<link href="favicon.ico" rel="icon" type="image/x-icon" />

</head>

<body>
<!-- cut for readablitiy -->
</body>
</html>

飞溅.php

<!DOCTYPE html>

<html lang="en">

<head>
<title>chrisRjones.com - Splash</title>

<script type="text/javascript">

function valForm() {

    if(!document.getElementById('splash_false').checked && !document.getElementById('splash_true').checked  ) {
        alert('You either like splash pages or you don\'t choose one ...please');
        return false;
    }
}

</script>

<!-- Javascript radiobutton form validation END -->


</head>

<body>
<img src="<?php echo $path . $img ?>" alt="" width="640" height="auto"  />
<h1>Refresh the page to enjoy more pictures.</h1><br />

<p>
<form name="tosplashornottosplash" action="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>



</body>
</html>

飞溅过程.php

<?php 

setcookie("visit", "true"); // delete cookie when browser / tab / session is clossed

$splashvar = $_POST["splash"];

if ( $splashvar == "false" ) {
    // create cookie - nosplash 1
    setcookie("nosplash", "false", time()+3600); // expires in one hour
}
    else {
        // create cookie - nosplash 0
        setcookie("nosplash", "true", time()+3600); // expires in one hour
    }

echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/index.php'";
echo "</script>";

?>

<!DOCTYPE html>

<html lang="en">

<head>
<title>chrisRjones.com - splash-process</title>

</head>

<body>
</body>
</html>
4

1 回答 1

0

如果在 Index.php 中,您可以尝试删除第二个。它实际上并没有做任何事情,因为他们,用户,已经在那里了。

于 2013-01-13T03:24:37.197 回答