Permalink
Browse files

Added PHP session heartbeat logic.

  • Loading branch information...
cubiclesoft committed Aug 10, 2018
1 parent 8eaeac6 commit 4a8143f442d3bd16c06d77451d53bf53d47477c5
Showing with 22 additions and 1 deletion.
  1. +22 −1 admin.php
View
@@ -47,6 +47,21 @@ function BB_InjectLayoutHead()
#menuwrap .menu .title { border-bottom: 2px solid #C48851; }
</style>
<?php
// Keep PHP sessions alive.
if (session_status() === PHP_SESSION_ACTIVE)
{
?>
<script type="text/javascript">
setInterval(function() {
jQuery.post('<?=BB_GetRequestURLBase()?>', {
'action': 'heartbeat',
'sec_t': '<?=BB_CreateSecurityToken("heartbeat")?>'
});
}, 5 * 60 * 1000);
</script>
<?php
}
}
// An example function used later on to demonstrate loading user information from a database.
@@ -60,7 +75,13 @@ function LoadUserDetails($info)
return BB_ProcessInfoDefaults($info, $defaults);
}
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "deleteexample")
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "heartbeat")
{
$_SESSION["lastts"] = time();
echo "OK";
}
else if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "deleteexample")
{
$id = (isset($_REQUEST["id"]) ? (int)$_REQUEST["id"] : 0);
// $db->Query("DELETE FROM userdetails WHERE id = ?", array($id));

0 comments on commit 4a8143f

Please sign in to comment.