PHP hash sha256 not working fine on server

I'm working on web services and an API requires a variable called $signature that is equal to:

// Signature is generated by SHA256 (Api-Key + Shared Secret + Timestamp (in seconds))

$signature = hash("sha256", $apiKey.$sharedSecret.time());

The rest of the code is as follows and it uses PECL 2.5.3:

$client = new http\Client;
$request = new http\Client\Request;

$request->setRequestUrl('https://api.test.hotelbeds.com/hotel-api/1.0/status');
$request->setRequestMethod('GET');
$request->setHeaders(array(
'cache-control' => 'no-cache',
'x-signature' => $signature,
'api-key' => '******************************',
'accept' => 'application/json'
));


$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();

The thing is, if I generate and var_dump the $signature value on my local server and then paste it like this:

'x-signature' => 'b67bfd70f9ba8564eddfde0aa02dffb8aa6e24f937886ae80f77efcee139e5e5',

And then run the script on the proyect server, it gives me a correct response, but if I just put:

'x-signature' => $signature,...

It gives me a "Not authorized error". I don't know what's going wrong, I have printed the time on the proyect server and the difference is like 10 numbers between each other, even if I put them equally, the problem persists.

The PHP version from my local server is 5.5.12 and the one from the proyect server is 5.4.16.

So, it could be the time function, which I don't think it is, or that the hash function differs from PHP versions, but that would be strange.

Please help.

Upvotes: 0

Views: 898

Answers (1)

I resolved it by changing the time zone on server and correcting the time on there.

Upvotes: 1

Related Questions