dragam0217 2014-12-29 03:00
浏览 54
已采纳

会话超时弹出 - 如何将JavaScript放入PHP?

i want to make comfirmation popup (yes/no button) in php if session already limit. 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 :

  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. how to put javascript of jquery inside 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>
  • 写回答

1条回答 默认 最新

  • dongyata3336 2014-12-29 03:09
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog