0

我想为每个唯一用户创建一个 24 小时出现一次弹出窗口的网站。为此,我使用 bPopup 和 cookie。我已经尝试了很多东西,现在我在代码中有点“迷失”了。你能帮我让它按应有的方式工作吗?

编码:

<?php
if (!isset($_COOKIE["Seen"])){
if ($_COOKIE['Seen'] != 'true') {
setcookie('Seen', 'false');
}
}
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script>
<script type="text/javascript" src="js/popup.js"> </script>
<LINK REL=StyleSheet HREF="style/style.css" TYPE="text/css" MEDIA=screen>


<html>
        <head>  </head>
        <body>
<!-- Element to pop up -->

<div <?php if(isset($_COOKIE["Seen"])) {
                    if ($_COOKIE['Seen'] == 'true') {echo 'style="all:none; visibility:hidden; display:none">';}
                    else {
                    echo ' id="element_to_pop_up">';
                    $value = 'true';
                    $expire = time()+60*60*24; 
                    setcookie('Seen', $value, $expire);
                    }
    }               
                     ?> 

    <a href="#"class="b-close" style="position:absolute; margin-top:5px; margin-left:550px;"><img src="./image/close.png"><a/>
    <iframe frameBorder="0" name="iFrame" width="600" height="500" src="welcome.php" scrolling="no"></iframe>

</div>

        </body>
    </html>
4

2 回答 2

1

怎么样的东西:

if(!isset($_COOKIE['popup']))
{
    setcookie('popup', time());
    echo '<script>alert(\'Here is your daily cookie :)\');</script>';
}
else
{
    if((time() - $_COOKIE['popup']) > (60*60*24))
    {
        setcookie('popup', time());
        echo '<script>alert(\'I see you enjoy our cookies, thanks for returning :)\');</script>';        
    }
}
于 2014-03-03T16:23:46.710 回答
0

试试这个代码。如果设置了 cookie,则无需检查两次,因为您在顶部对此进行了考虑并将其设置为 false。如果未设置或(出于某种原因)它不是“真”,则此代码会将其设置为假。然后,到了一半,它只需要检查它是否是真的。

最好只为每个条件打开一个单独的打开 div,否则它会很快变得非常混乱和草率。

<?php
if (!isset($_COOKIE['Seen']) || $_COOKIE['Seen'] != 'true') {
    setcookie('Seen', 'false');
}
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script>
<script type="text/javascript" src="js/popup.js"> </script>
<LINK REL=StyleSheet HREF="style/style.css" TYPE="text/css" MEDIA=screen>


<html>
<head>  </head>
<body>
<!-- Element to pop up -->

<?php
if ($_COOKIE['Seen'] == 'true') {echo '<div style="all:none; visibility:hidden; display:none">';}
else {
    echo '<div id="element_to_pop_up">';
    $value = 'true';
    $expire = time()+60*60*24;
    setcookie('Seen', $value, $expire);
}
?>

<a href="#"class="b-close" style="position:absolute; margin-top:5px; margin-left:550px;"><img src="./image/close.png"><a/>
    <iframe frameBorder="0" name="iFrame" width="600" height="500" src="welcome.php" scrolling="no"></iframe>

    </div>

</body>
</html>
于 2014-03-03T16:23:29.917 回答