简体   繁体   English

会话超时弹出窗口-如何将javascript放在php中?

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

i want to make comfirmation popup (yes/no button) in php if session already limit. 如果会话已经限制,我想在php中进行确认弹出窗口(是/否按钮)。 If the user click yes button in popup it stay in the website or refresh session, if click no, session terminated. 如果用户在弹出窗口中单击“是”按钮,它将停留在网站或刷新会话中;如果单击“否”,则会话终止。 How can i do this?.. below is my php code : 我该怎么办?..以下是我的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'];
    }

my problems i cannot put javascript code inside the php. 我的问题我不能把javascript代码放在php中。 how to put javascript of jquery inside php? 如何把jQuery的JavaScript里面的PHP?

this is my code i want : 这是我想要的代码:

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

Try below code 试试下面的代码

       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          
  }

It must be work. 它一定是工作。 First check alert box. 首先选中警报框。

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

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