I had a server where i have a php file to which i pass some header variables and read it in the PHP file as follows...
$_SERVER["HTTP_API_KEY"]
If i pass API_KEY in my header data i get the value in server as $_SERVER["HTTP_API_KEY"]. Now my code has been moved to new server and there i do not see $_SERVER["HTTP_API_KEY"] in my $_SERVER array!
It could be either PHP module or Apache module that i may need to configure with server i believe. I tried to find solution but unlucky to get one yet.
Let me know if anyone knows exactly what it is...
I would give the getallheaders function a try!
If you want to add the key back into the $_SERVER array, just add this to the top of your file.
<?php
if(!isset($_SERVER['HTTP_API_KEY']) && isset(getallheaders()['API_KEY']))
$_SERVER['HTTP_API_KEY'] = getallheaders()['API_KEY'];
?>
To grab the first available key.
<?php
if(isset($_SERVER['HTTP_API_KEY']))
$key = $_SERVER['HTTP_API_KEY'];
elseif(isset(getallheaders()['API_KEY']))
$key = getallheaders()['API_KEY'];
else
die('Key not found.');
?>
Adapted to include keys from Get and Post requests.
<?php
if(isset($_SERVER['HTTP_API_KEY']))
$key = $_SERVER['HTTP_API_KEY'];
elseif(isset(getallheaders()['API_KEY']))
$key = getallheaders()['API_KEY'];
elseif($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['API_KEY']))
$key = $_POST['API_KEY'];
elseif(($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'POST') && isset($_GET['API_KEY']))
$key = $_GET['API_KEY'];
else
die('Key not found.');
if($key !== '12345')
die('Invalid key.');
echo 'Hello world!';
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With