0

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?

4

2 回答 2

0

我终于找到了解决方案。我使用了这个站点的 SessionKeepAliveListener 。我通过 AJAX 调用控制器,如下所示:

function slowAlert() {
            setTimeout(logout, 40000)
          var r=confirm("You will be logout in 20s!");
          if (r==true)
          {
            $.ajax({
                url: "{{ url('_demo_hello') }}",
                xhrFields: {
                    withCredentials: true
                 }
            });
            alert("You wont be logout");
          }
        }

控制器非常简单:D

/**
 * @Route("/check", name="_demo_hello")
 */
public function checkAction()
{      
    $response = new Response();

    return $response;
}
于 2013-08-02T11:30:22.947 回答
0

我认为这不是一个好的解决方案(如果可行的话),但是 symfony 中的会话 cookie 被称为“PHPSESSID”。尝试将此 cookie 的生命周期设置为所需的时间?我使用这种方法将我的会话通过 Drupal 和 Varnish 传递给客户端,所以我认为它可以延长会话的生命周期。

问候, 皮克莫

于 2013-07-29T09:50:49.090 回答