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 Commented Jan 6, 2016 at 11:47
  • @JoséTrindade exactly what I wanted. Thank you. Commented Jan 6, 2016 at 12:06
  • Here is new docs: CI3, CI2. 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(); Commented Apr 29, 2017 at 11:59

3 Answers 3

24

Simply use,

$this->input->request_headers();

Sign up to request clarification or add additional context in comments.

5 Comments

how i set value in CI at time of form submit to get value in $this->input->request_headers();
@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.
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
what is used in CI v4? I have tried headers, header and getHeaderLine to get customer header but didn't get response
get specific value $this->input->request_headers()['Host']
2

If you are sending values from form submit,

$_REQUEST will help you

or

    $this->input->post();
    $this->input->get();

1 Comment

Thanks but $this->input->request_headers(); was what I was looking for.
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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.