简体   繁体   English

页面加载时的弹出框

[英]A popup box on page load

I am using a feature of popup box in my project. 我在项目中使用弹出框的功能。 When a user come to the site a popup box apears on the top of the page hiding the rest of the content. 当用户来到站点时,页面顶部弹出一个对话框,隐藏其余内容。 In that popup form the user has to give a download key. 在该弹出窗口中,用户必须提供下载密钥。 if the user has the key he can go forward otherwise he cannot see anything else. 如果用户有钥匙,他可以前进,否则他看不到其他任何东西。 When the user provide the key he goes to the main page. 当用户提供密钥时,他将转到主页。 Now the problem is once the user comes to the main page after providing the key and when he clicks again on the header again the page is reloaded and again tht popup form comes. 现在的问题是,一旦用户在提供密钥后进入主页,当他再次单击标题时,页面将重新加载,并且弹出表单再次出现。 How can I prevent it to apear again if some user has already given the download key . 如果某些用户已经提供了下载密钥,如何防止它再次出现。 I am using php with code igniter. 我在代码点火器中使用php。 My code 我的密码

<?php if($download_key != null && !isset($_POST['popup'])){?>
    <script type="text/javascript">
        $(document).ready(function(){  
                loadPopup();    
        });  
    </script>
<?php } ?>

downlaod key is database column and popup is a hidden input that is set when the form is submitted on the popup box. downlaod键是数据库列,而popup是一个隐藏的输入,当在弹出框上提交表单时设置。 The form that appears on popup box is as 弹出框上显示的形式为

<form name="form" method="post" onsubmit="return validateForm('<?php echo $download_key ?>')"> 
 <div style="width:530px;">
     <input style="display:none; height:25px;" id="downloadkey" name="downloadkey" type="text" />
     <input style="display:none;" type="submit" id="submit" name="submit" value="<?php echo $variable['QUESTION_BUTTON']['value']?>"/>
  </div>
</form>

Any ideas ? 有任何想法吗 ?

Thanks 谢谢

You should have a session_start() at the beginning of pageload 您应该在页面加载开始时使用session_start()

EDIT: changed a bit 编辑:改变了一点

session_start();

//check if key has already been seen:

if(isset($_SESSION['download_key']) && $_SESSION['download_key'] != null ...

// then if not check if the key is submitted

else if ( isset($_POST['popup']) ... // and other checks

   // set session variable
   $_SESSION['download_key'] = $key;

else

   // load the ask for key page

Set a session variable, and check to see if it's present, as it will be on subsequent pageloads, and just skip the popup etc. 设置一个会话变量,并检查它是否存在,因为它将出现在后续的页面加载中,只是跳过弹出窗口等。

<?php 
    session_start();
    if ($download_key != null && !isset($_POST['popup'])) {
       if ($_SESSION['key_ok']!=true) {  //you should check if it's set first with isset()
          echo '<script type="text/javascript">';
          echo '$(document).ready(function(){';
          echo 'loadPopup();';
          echo '});';
          echo '</script>';
       }
       if (key_is_correct) {$_SESSION['key_ok']=true}
    } 
?>

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

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