I made a simple PHP app that provides RESTful API for registering, logging in and updating user's geolocation. I tested it out with MySQL database on a local Apache sever and everything was fine.
Recently I migrated the PHP code to an online host HostGator. Part of my code stopped working when it involves recognizing HTTP request header. Like this:
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Authorization: f0cc696e44f76f9638331b5487f4b01d
Content-Type: application/x-www-form-urlencoded
Accept: */*
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4
I wrote my PHP code such that it reads the api-key under header Authorization. It worked fine on my local server but reported api-key missing when the same code was migrated on HostGator
I suspect there may be certain settings that are default in my local environment but need to be set explicitly in HostGator. Here's my current .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
AddType application/x-httpd-php54 .php
I'm using XAMPP for local sever and database, and Chrome extension Advanced Rest Client for sending HTTP requests.
Edit: My code to retrieve the header value:
$headers = apache_request_headers();
if (isset($headers['Authorization'])) {
$api_key = $headers['Authorization'];
// validating api key
// ...
} else {
// api key is missing in header
// ...
}