簡體   English   中英

會話超時彈出窗口-如何將javascript放在php中?

[英]Session Timeout Popup - How to put javascript in php?

如果會話已經限制,我想在php中進行確認彈出窗口(是/否按鈕)。 如果用戶在彈出窗口中單擊“是”按鈕,它將停留在網站或刷新會話中;如果單擊“否”,則會話終止。 我該怎么辦?..以下是我的php代碼:

  if (isset($_SESSION['LAST_ACTIVITY1']) && (time() - $_SESSION['LAST_ACTIVITY1'] > 7200)) {

        if (isset($_SESSION['member_id'])) {

***<script>comfirmation popup code in here</script>***

            session_unset();     // unset $_SESSION variable for the run-time
            session_destroy();   // destroy session data in storage


            header('Location: '.AT_BASE_HREF.'login.php?loginexpired=true');
            exit;
        }
        //echo "awa";
    } else {
        //echo "aba" . $_SESSION['LAST_ACTIVITY1'];
    }

我的問題我不能把javascript代碼放在php中。 如何把jQuery的JavaScript里面的PHP?

這是我想要的代碼:

         <script type='text/javascript'>

var answer = confirm ("Are you having fun?")
if (answer)
alert ("Woo Hoo! So am I.")
else
alert ("Darn. Well, keep trying then.")

  session_unset();     // unset $_SESSION variable for the run-time
  session_destroy();   // destroy session data in storage
    //header('Location: '.AT_BASE_HREF.'login.php?loginexpired=true');
     window.location.href="<?php AT_BASE_HREF.'login.php?loginexpired=true'; ?>"; 

// -->

         </script>

試試下面的代碼

       if (isset($_SESSION['member_id'])) {
?>
         <script type='text/javascript'>

           alert('test');

         </script>
<?php
        session_unset();     // unset $_SESSION variable for the run-time
        session_destroy();   // destroy session data in storage



 ?>
           <script type='text/javascript'>
              location.href="<?php echo AT_BASE_HREF.'login.php?loginexpired=true'?>";
           </script>

  <?php          
  }

它一定是工作。 首先選中警報框。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM