简体   繁体   English

php或javascript会话规则弹出窗口

[英]php or javascript session rules popup

I just created a Pup-up using Magnific Pop-up. 我刚刚使用Magnific Pop-up创建了一个Pup-up。 I now have to set the session rules: 我现在必须设置会话规则:

  • The popup has to appear 5 seconds after the user lands in the website and has not to be shown for the rest of session 用户登陆网站后,弹出窗口必须显示5秒钟,其余的会话均不显示

  • The popup has to appear 5 times for each user's session: as soon as the user does not perform any action on the popup or the user closes the popup 5 times, the popup doesn't have to appear anymore. 每个用户会话的弹出窗口必须出现5次:只要用户不对弹出窗口执行任何操作,或者用户关闭弹出窗口5次,则不再必须出现弹出窗口。

Can you help me please? 你能帮我吗? Thanks in advance! 提前致谢!

Below is a simple solution, however depending on how your site is set up other page loads and/or ajax calls could increment the counter, so be conscious of when/where you increment the session variable $_SESSION['show_popup_count'] 以下是一个简单的解决方案,但是根据您网站的设置方式,其他页面加载和/或ajax调用可能会增加计数器,因此请注意何时/何地增加会话变量$_SESSION['show_popup_count']

<?php
session_start();
if(isset($_SESSION['show_popup_count'])){
    //handle completely new session here
    $_SESSION['show_popup_count']=0;
}
$_SESSION['show_popup_count'] += 1;

//expose value to javascript
?><script type="text/javascript">
    var popupCounts = <?php echo $_SESSION['show_popup_count']; ?>;
</script><?php
.... //continue on with rest of code

then here is your additional javascript 然后这是您的其他JavaScript

if(popupCounts<6){
    //code to show popup here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM