0

I'm new with php and MySQL. I have created Restful API which I need for connecting my application with server, and everything was working fine on localhost, but when I moved to server and host files online, I can't get anything to work there.

I'm using Slim library for building Restful API by the way.

Here I'm checking if Authorization key is there in Http request and also checking if it is valid:

function authenticate(\Slim\Route $route) {
// Getting request headers
$headers = apache_request_headers();
$response = array();
$app = \Slim\Slim::getInstance();

// Verifying Authorization Header
if (isset($headers['Authorization'])) {
    $db = new DbHandler();

    // get the api key
    $api_key = $headers['Authorization'];
    // validating api key
    if (!$db->isValidApiKey($api_key)) {
        // api key is not present in users table
        $response["error"] = true;
        $response["message"] = "Access Denied. Invalid Api key";
        echoResponse(401, $response);
        $app->stop();
    } else {
        global $user_id;
        // get user primary key id
        $user_id = $db->getUserId($api_key);

    }
} else {
    // api key is missing in header
    $response["error"] = true;
    $response["message"] = "Api key is misssing";
    echoResponse(400, $response);
    $app->stop();
}
}

Even if i put Authorization key in Http request, I'm getting message that Api key is missing.

This is my htaccess file:

    RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Dusan Dimitrijevic
  • 3,169
  • 6
  • 22
  • 46

0 Answers0