1. Go to this page and download the library: Download torugo/jwt 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/ */
torugo / jwt example snippets
use Torugo\JWT\JWT;
use Torugo\JWT\Enums\JwtAlg;
$key = "example_key_Jr6QWaxb7pgerDJgL";
$payload = [
"sid" => "session_id",
"uid" => "user_id",
// ... more data
"iat" => 1724972934, // if not present, this library adds automatically
"nbf" => 1724000000, // if not present, this library adds automatically
"ext" => 1724973234, // if not present, this library adds automatically
];
$jwt = JWT::encode($payload, $key, JWTAlg::HS256);
try {
$payload = JWT::decodePayload($jwt, $key);
} catch (ExpiredTokenException $e) {
// When using RS256, RS384 or RS512 you must also pass the privateKey
// On HS algorithms it is not needed
$token = JWT::refreshToken($token, $publicKey, $privatekey);
} catch (\Throwable $e) {
// Handle exception
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.