PHP Token Generator Code

Example PHP code to generate an API Token

<?php

    /*
            The secret that should already have been provided
    */
$tokenConfig['secret'] = 'testtoken';

/*

            IP address of the user making the request
*/
$tokenConfig['ipaddress'] = '1.2.3.4';

/*

            Timestamp in milliseconds - use date('U')*1000 to get current time
*/
$tokenConfig['timestamp'] = "1385554442935"; //date('U')*1000;

/*
            Generated token
*/
$token = hash_hmac('md5', implode(':', $tokenConfig), $tokenConfig['secret']);

?>

Example

Running this code with the timestamp 1385554442935 yields the value:

51cc11786ddac11c7af450ec5b42aee4

Last updated

Was this helpful?