Question

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?

Was it helpful?

Solution 2

@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";
}
?>

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top