MY_Controller codeigniter 3中的set_header不起作用

时间:2015-12-07 04:57:26

标签: codeigniter

我在application / core

上扩展了这样的ci_controller
class MY_Controller extends CI_Controller {

public function __construct() {
    parent::__construct();
    $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
    $this->output->set_header("Pragma: no-cache");
}

}

class Public_Controller extends MY_Controller {
   public $layout = 'layout';

}  

class Surveyor_Controller extends MY_Controller {

 public $layout = 'surveyor/template/layout';

 public function __construct() {
    parent::__construct();

    $login_status = $this->session->userdata('login_status');
    $group = $this->session->userdata('group');

    if (($login_status !== true) && ($group !== 3)) {
        redirect(base_url());
    }

    // Pastikan hanya "operator" yang boleh mengakses.
    if ($group !== '3') {
        $this->session->set_flashdata('error', 'Anda tidak berhak mengakses halaman ini!');
        redirect(base_url());
    }
  }

}

我的问题是,后退箭头页面仍然有效 所以,在应用程序/控制器中:我创建了一个像这样的新类:

class C_surveyor extends Surveyor_Controller {

public $data = array(
    'halaman' => 'home',
    'main_view' => 'surveyor/v_home'
);

public function __construct() {
    parent::__construct();
    $this->load->helper('form');
    $this->load->model('m_surveyor');
}

public function index() {
    $this->load->view($this->layout, $this->data);
}

只是说用户已经在索引上,并且clik箭头返回所以获取登录页面。标题不起作用。当用户点击右边的arraow时,它仍然会得到索引页面。 我在哪里错过了? 任何解决方案如此赞赏

1 个答案:

答案 0 :(得分:0)

尝试添加此代码而不是那两行,

$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache"); 

参考This