2014-03-02 42 views
1

我有這個問題:我無法找到如何隱藏只在會話開始時出現的div。所以我有一個X按鈕用於關閉,當頁面刷新時,div再次出現!但我不想停止這個會議。 我的代碼:當用戶會話存在時隱藏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> 

回答

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我無法猜測它很好,但這應該提供一個起點:

<?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 
    } 

這是假設你想th div輸出,但不顯示在隨後的負載。

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>"; 
} 

?> 
0

試試這個

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

希望它會工作