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
  How to Stop Sending E-Mail Spam using PHP mail function Kingsolomon 1 671 11-12-2018, 04:38 PM
Last Post: Solomon
  Multiple file upload in php Kingsolomon 1 546 11-08-2018, 03:01 PM
Last Post: Solomon
  How to limit text length in php and provide 'Read more' link Kingsolomon 0 649 10-31-2018, 02:08 PM
Last Post: Kingsolomon
  How to read more / hide text using Jquery and PHP Kingsolomon 0 502 10-31-2018, 02:06 PM
Last Post: Kingsolomon
  Download simple HTML email templates Kingsolomon 0 556 10-31-2018, 02:05 PM
Last Post: Kingsolomon

Forum Jump:


Users browsing this thread:
1 Guest(s)

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