在symfony2中注销后我无法清除我的会话

LL *_*neh 1 php symfony

当我尝试在symfony2中注销我的会话支持被完全清除但是如果我点击浏览器后退按钮我可以进入我以前的会话

 firewalls:
    main:
        pattern: /.*
        form_login:
            login_path: /login
            check_path: /login_check
            default_target_path: /hrs/applyleave/
        logout: 
            path: /logout
            target: /login
            path: security_admin_logout
            target: security_admin_login
            invalidate_session: true
            delete_cookie:~
        security: true
        anonymous: true
Run Code Online (Sandbox Code Playgroud)

有什么我想念的吗?

sig*_*y85 5

我最近遇到了这个小问题,在几个帖子的帮助下,我提出了以下解决方案.

为了澄清这里的问题,在退出安全区域后,我们希望通过单击后退按钮来防止再次查看任何安全的先前页面.为此,不得将这些先前页面存储在客户端缓存中.我们需要拦截每个Symfony页面响应,检查它是否是一个安全页面,如果是,请设置标题以返回no-cache.

第一步,设置响应监听器类:

namespace AppBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

class ResponseListener
{
    public function onKernelResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($this->disableThisPageCache($request->getPathInfo())) {
            $headers = $event->getResponse()->headers;
            $headers->set('Cache-Control', 'no-cache, no-store, must-revalidate'); // HTTP 1.1.
            $headers->set('Pragma', 'no-cache'); // HTTP 1.0.
            $headers->set('Expires', '0'); // Proxies.
        }
    }

    private function disableThisPageCache($currentPath)
    {
        $paths = array('/admin', '/customer');

        foreach ($paths as $path) {
            if ($this->checkPathBegins($currentPath, $path)) {
                return true;
            }
        }

        return false;
    }

    private function checkPathBegins($path, $string)
    {
        return substr($path, 0, strlen($string)) === $string;
    }
}
Run Code Online (Sandbox Code Playgroud)

第2步,将其注册为服务:

app.filter_response_listener:
    class: AppBundle\EventListener\ResponseListener
    tags:
        - { name: kernel.event_listener, event: kernel.response }
Run Code Online (Sandbox Code Playgroud)

步骤3,将$paths数组设置为包含应用程序的安全路径.如果您需要找到这些,请查看access_control部分下的security.yml文件.

使用Symfony Security服务可能有更好的方法来检查页面是否在安全区域中,但此解决方案适用于我的应用程序.

感谢这些帮助我的帖子: