9

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.

5
  • 1
    use CI's Input class: $this->input->request_headers(); (or apache_request_headers() if available). Commented Jan 6, 2016 at 11:46
  • Read this
    – Saty
    Commented Jan 6, 2016 at 11:47
  • @JoséTrindade exactly what I wanted. Thank you.
    – john
    Commented Jan 6, 2016 at 12:06
  • Here is new docs: CI3, CI2.
    – Tpojka
    Commented Jan 6, 2016 at 13:07
  • how i set value in CI at time of form submit to get value in $this->input->request_headers();
    – sunil
    Commented Apr 29, 2017 at 11:59

3 Answers 3

24

Simply use,

$this->input->request_headers();

5
  • how i set value in CI at time of form submit to get value in $this->input->request_headers();
    – sunil
    Commented Apr 29, 2017 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
    Commented Apr 30, 2017 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
    Commented Apr 30, 2017 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 Commented Jul 15, 2021 at 7:42
  • get specific value $this->input->request_headers()['Host'] Commented Dec 21, 2021 at 13:13
2

If you are sending values from form submit,

$_REQUEST will help you

or

    $this->input->post();
    $this->input->get();
1
  • Thanks but $this->input->request_headers(); was what I was looking for.
    – john
    Commented Jan 6, 2016 at 13:13
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.