Sologet Forum
How to session timeout warning with countdown using PHP, Ajax and HTML - Printable Version

+- Sologet Forum (https://www.sologet.com)
+-- Forum: Programming (https://www.sologet.com/Forum-Programming)
+--- Forum: PHP Programming & Tutorials (https://www.sologet.com/Forum-PHP-Programming-Tutorials)
+--- Thread: How to session timeout warning with countdown using PHP, Ajax and HTML (/Thread-How-to-session-timeout-warning-with-countdown-using-PHP-Ajax-and-HTML)



How to session timeout warning with countdown using PHP, Ajax and HTML - Kingsolomon - 09-29-2018

In this tutorial we will show you how to display session timeout warning with countdown using PHP, Ajax and HTML.When user logged in using login form we display a countdown and after the countdown end user will be logged out automatically. 
HTML and jQuer Code

Code:
<html>
   <head>
       <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
       <script type="text/javascript">
           function start_countdown()
           {
               var counter = 10;
               myVar = setInterval(function ()
               {
                   if (counter >= 0)
                   {
                       document.getElementById("countdown").innerHTML = "You Will Be Logged Out In <br>" + counter + " Sec";
                   }
                   if (counter == 0)
                   {
                       $.ajax
                       ({
                           type: 'post',
                           url: 'logout.php',
                           data: {
                               logout: "logout"
                           },
                           success: function (response)
                           {
                               location.reload();
                           }
                       });
                   }
                   counter--;
               }, 1000)
           }
       </script>
   </head>
   <body>
       <?php
       if (@$_SESSION['password'] == "123456" && @$_SESSION['name'] == "123456") {
           ?>
           <script>start_countdown();</script>
           <p id="countdown"></p>
           <?php
       }
       ?>
   </body>
</html>

PHP Code (logout.php)


Code:
<?php
if(isset($_POST['logout']))
{
unset($_SESSION['name']);
unset($_SESSION['password']);
echo "success";
exit();
}
?>




RE: How to session timeout warning with countdown using PHP, Ajax and HTML - Shugudun - 04-14-2020

This is a good skill also

https://jiji.ng/gwarinpa/computer-and-it-services/start-a-blog-in-minutes-with-this-php-script-cBWQBOeRIdMtzsJbiDV4mHTK.html