在存在用户会话时隐藏div

时间:2014-03-02 14:32:06

标签: php jquery session

我有这个问题:我无法找到如何隐藏会话开始时出现的div。所以我有一个X按钮用于关闭,当页面刷新时,div再次出现!但我不想停止会议。 我的代码:

<div id="got-points" style="display:<?php echo (isset($customer) && !empty($customer) && isset($customer['customer']) && !empty($customer['customer'])) ? 'block' : 'none'; ?>"> // Checks if session is active
<div class="got-points-bg" style="display: visible;">
    <div class="got-points-box">
        <img class="got-points-close" src="<?php echo base_url();?>static/images/i8.png" /> //Close Button

           My text here

    </div>
  </div>
</div>

和js

  <script>
$(document).ready(
    function() {
        $(".got-points-close").click(function() {
            $(".got-points-bg").hide("fast");
        });
    });
  </script>

3 个答案:

答案 0 :(得分:1)

如果是刷新则很容易;只是在PHP会话中执行;像这样:

HTML:

<div id="got-points" style="display:<?php echo (isset($customer) && !empty($customer) && isset($customer['customer']) && !empty($customer['customer']) && empty($_SESSION['first_load'])) ? 'block' : 'none'; ?>"> // Checks if session is active
<div class="got-points-bg" style="display: visible;">
    <div class="got-points-box">
        <img class="got-points-close" src="<?php echo base_url();?>static/images/i8.png" /> //Close Button

           My text here

    </div>
  </div>
</div>

然后在你的PHP之前(比如在登录/会话开始时) - 这显然需要大量的编辑,因为你没有包含你的PHP我不能很好地猜测它,但这应该提供一个起点:< / p>

<?php
    //load user check pseudo code
    if !empty($_SESSION[user]) and whatever other checks... {
        $_SESSION['first_load'] = False; //important line number 2
    }
    //login pseudo code to demonstrate placement within your code
    if user & pass = valid {
        $_SESSION['first_load'] = True; //important line number one
    }

假设您想要div输出但不会在后续加载中显示。

答案 1 :(得分:0)

有趣的问题,这样的事情怎么样?

<?php

if(isset($_SESSION['variable'])){
    sleep(3); /* Duration(in seconds) div is displayed for */
    echo
    "<script>
        $( document ).ready(function() {
            $(".got-points-bg").hide("fast");
        });
   </script>";
}

?>

答案 2 :(得分:0)

试试这个

<?php error_reporting(0); session_start(); if(empty($_SESSION['user'])) echo "<div id='togglediv'> My text here </div>"; ?>    

希望它能运作