I am trying to extend sesion_liftime before Symfony2 sesion will be destroyed.
I am showing the user that he will be log out in few seconds, and when he/she confirm to extend the sesion I send an ajax request to controller which should extend the sesion. But the problem is that the request is not working.
I try few diferent solutions but none of them worked.
<script type="text/javascript">
var timeoutID;
function delayedAlert() {
timeoutID = window.setTimeout(slowAlert, 15000);
}
function slowAlert() {
setTimeout(logout, 5500)
var r=confirm("You will be logout in 5 seconds!");
if (r==true)
{
$.ajax({
url: 'http://localhost/interactivo/web/app_dev.php/check',
xhrFields: {
withCredentials: true
}
});
alert("You wont be logout");
}
}
function logout() {alert("You are logout");};
delayedAlert();
</script>
/**
* @Route("/check")
*/
public function indexAction()
{
// FIRST ATTEMPT
// $value = 'something from somewhere';
//
// setcookie("TestCookie", $value);
// setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
// setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);
// SECOND ATTEMPT
// header('Content-type: text/html; charset=utf-8');
// echo 'TEST';
// THIRD ATTEMPT
$session = $this->container->get('session');
$lastUsed = new \DateTime();
$lastUsed->setTimestamp($session->getMetadataBag()->getLastUsed());
return $this->render('GLHomeBundle:Default:sesion.html.twig', array( 'entities'=> $lastUsed));
}
What I'm doing wrong?