我正在尝试使用codeigniter框架设置自己的自定义请求头。
我正在使用$this->input->request_header();
函数来查看所有请求的标头。
我认为提问者希望在客户端设置他的自定义头,并在服务器端使用它。只需通过一些包(如jQuery (将标题设置为html即可
$.ajaxSetup({
headers: { "custom_header_name": "myValue" }
});
在服务器端通过Codeigniter 获取
$this->input->request_headers()['custom_header_name']
您可以使用output
类。注意,与其他类/库不同,output
类是由系统自动加载的,因此您不必这样做
以下是设置不同标题的示例(来自CodeIgniter的网站)
$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');