简体   繁体   中英

Session Timeout Popup - How to put javascript in 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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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