8

How can I print the values set in the header of a received request using CodeIgniter?

I tried print_r($_SERVER); which doesn't help me. I'm hoping there's a different way using CI.

john
  • 1,561
  • 3
  • 20
  • 44

3 Answers3

22

Simply use,

$this->input->request_headers();

john
  • 1,561
  • 3
  • 20
  • 44
  • how i set value in CI at time of form submit to get value in $this->input->request_headers(); – sunil Apr 29 '17 at 11:59
  • @sunil you can't. CI is for the back end of your application and requests (including the request header) are created from the front end (usually via AJAX). Ask a new question if you need help. – john Apr 30 '17 at 14:09
  • Thanks @john , yes its working with ajax , but as you said in form it can't work , so thereis nothing to do with curl or something else if i wish o not use jquery ajax – sunil Apr 30 '17 at 19:05
  • what is used in CI v4? I have tried headers, header and getHeaderLine to get customer header but didn't get response – Pragnesh Chauhan Jul 15 '21 at 07:42
  • get specific value $this->input->request_headers()['Host'] – Billu Dec 21 '21 at 13:13
2

If you are sending values from form submit,

$_REQUEST will help you

or

    $this->input->post();
    $this->input->get();
teshvenk
  • 403
  • 3
  • 8
0

To receive all values from the request header

$valuesInHeader = $this->input->request_headers();

To get specific value from request header

$hostValueInHeader = $this->input->request_headers()['Host'];
//"Host" is a key of a value, you can use your required key.
Billu
  • 2,733
  • 26
  • 47