dongyun9120 2015-03-11 15:38
浏览 195

Symfony2 - 注销并清除缓存+阻止后退按钮

I try to kill browser cache when user logout. I implement the LogoutSuccessHandlerInterface to extends the onLogoutSuccess method. There is no error but when I logout, I can press back button in browser and I see my profil page => If I refresh this page, I am automatically redirected, so I am correctly logged out.

security.yml

logout:
    path:   /logout
    target: /
    invalidate_session: true
    success_handler: project_user.handler.logout_handler

services.yml

project_user.handler.logout_handler:
    class:  Project\UserBundle\Handler\LogoutHandler

Project/UserBundle/Handler/LogoutHandler.php

<?php
namespace Project\UserBundle\Handler;

use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;

class LogoutHandler implements LogoutSuccessHandlerInterface
{
  public function onLogoutSuccess( Request $request )
  {
    $response =  new RedirectResponse( '/' );

    $response->headers->addCacheControlDirective( 'no-cache', true );
    $response->headers->addCacheControlDirective( 'max-age', 0 );
    $response->headers->addCacheControlDirective( 'must-revalidate', true );
    $response->headers->addCacheControlDirective( 'no-store', true );

    return $response;
  }
}

I try with this solution and that works perfectly, but this method is called for each requests (many time for each pages) and caused slowdowns. Please help!

thx

  • 写回答

2条回答 默认 最新

  • dop83362 2015-06-05 15:39
    关注

    A method I have used with some success is simply to redirect to the previous page after logout. If the previous page was secured, your auth system will then redirect back to the login page. Now when you press the back button you should hit the login page again.

    See my post here for an example in Laravel: https://laracasts.com/discuss/channels/requests/back-button-browser

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀