0

I have made an API using Phil Sturgeon REST Api which uses the codeignitor framework. Every request made to my api should have X-API-KEY:{api key} in the request header. Is there anyway I can get the api key of a request so that the api can identify the user who has generated the api key in my system.Is there anyway I get get the X-API-KEY value from the header?

Piya
  • 1,134
  • 4
  • 22
  • 42

3 Answers3

2

You can do this in CodeIgniter to get header specific key value

$key_value = $this->input->get_request_header("X-API-KEY");

from CodeIgniter documentation here https://www.codeigniter.com/user_guide/libraries/input.html#CI_Input::get_request_header

Neri
  • 738
  • 1
  • 8
  • 19
1

@piya I am not sure this could help you out or not.. but give it a try..

<?php
$headers = apache_request_headers();

foreach ($headers as $header => $value)
{
    echo "$header: $value <br />\n";
}
?>
Nishant Solanki
  • 2,119
  • 3
  • 19
  • 32
1

Try $_SERVER['HTTP_X_API_KEY']..

$key_name = 'HTTP_'.strtoupper(str_replace('-', '_', $api_key_variable));

The above is how the REST_Controller finds out the key from the request headers.

Damian
  • 11
  • 1