1. Go to this page and download the library: Download controlabs/jwt-helper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Controlabs\Http\Exception\Unauthorized; // composer JWTHelper(PRIVATE_KEY, PUBLIC_KEY);
try {
$payload = $helper->decode($_POST['token']);
} catch(ExpiredToken $exception) {
throw new Unauthorized('Inalid token');
}
// or use $helper->decode($_POST['token'], true) to supress errors
if($payload['user_agent'] !== $_SERVER['HTTP_USER_AGENT']) {
throw new Unauthorized('User agent is invalid.');
}
echo json_encode([
'user_id' => $payload['user_id'],
'group_id' => $payload['group_id']
]);
use Controlabs\Helper\JWT as JWTHelper;
$helper = new JWTHelper(PRIVATE_KEY, PUBLIC_KEY);
// Use only for logs or specific purposes because it extracts content without validating the token.
$payload = $helper->payload($_POST['token']);
echo json_encode([
'user_id' => $payload['user_id'],
'group_id' => $payload['group_id']
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.