Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP GetHeaders() return keys in Uppercase on production server

I'm trying to get apikey in header. My problem is when i try to get that key, it gives me different parameter on both live server and local server.

Code :

$apikey = $this->request->getHeaders();
print_r($apikey);

Local Result

Array
(
    [Apikey] => *************
)

Live Result :

Array
(
    [APIKEY] => *************

)

See the KEY, on local I got Apikey first letter capital, on live APIKEY whole string is capital.

This creates a problem when i tried to access a key from an array.

like image 420
Mr. Engineer Avatar asked Oct 22 '25 03:10

Mr. Engineer


1 Answers

I had the same issue. Still dont know why it occurs in some servers. So you could do:

$apikey = array_change_key_case(getHeaders(), CASE_LOWER);

This way you will always receive the keys in lowercase.

like image 65
Flávio Ribeiro Avatar answered Oct 24 '25 19:10

Flávio Ribeiro