Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to session timeout warning with countdown using PHP, Ajax and HTML
#1
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();
}
?>

To Purchase Credit Click here , For how to make money on Sologet forum Click here 

HIRE ME FOR WEBSITE DESIGNING USE THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
  


Messages In This Thread
How to session timeout warning with countdown using PHP, Ajax and HTML - by Kingsolomon - 09-29-2018, 07:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TIPS How to add one day in current date using php Kingsolomon 1 784 04-14-2020, 01:16 AM
Last Post: Shugudun
  TIPS How to get Page Loading Time using PHP Kingsolomon 2 940 04-14-2020, 01:01 AM
Last Post: Shugudun
  How to read more / hide text using Jquery and PHP Kingsolomon 1 808 04-14-2020, 12:57 AM
Last Post: Shugudun
  How to limit text length in php and provide 'Read more' link Kingsolomon 1 995 04-14-2020, 12:43 AM
Last Post: Shugudun
  How to Stop Sending E-Mail Spam using PHP mail function Kingsolomon 2 1,157 04-14-2020, 12:40 AM
Last Post: Shugudun

Forum Jump:


Users browsing this thread:
1 Guest(s)

How to session timeout warning with countdown using PHP, Ajax and HTML00