PHP code example of musa11971 / php-jwt-decoder

1. Go to this page and download the library: Download musa11971/php-jwt-decoder 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/ */

    

musa11971 / php-jwt-decoder example snippets


$payload = JWTDecoder::token($jwt)
                ->withKey($publicKey)
                ->decode();

$payload = JWTDecoder::token($jwt)
                ->withKey($key)
                ->decode();

$keys = [...]; // Array of keys

$payload = JWTDecoder::token($jwt)
                ->withKeys($keys)
                ->decode();

$payload = JWTDecoder::token($jwt)
                ->withKey($key)
                ->ignoreExpiry()
                ->decode();

$payload = JWTDecoder::token($jwt)
                ->withKey($key)
                ->ignoreNotValidBefore()
                ->decode();

$payload->has('username'); // true
$payload->has('date_of_birth'); // false

$payload->get('username'); // 'John'

$payload->toArray();

/*
 * [
 *   'username'     => 'John',
 *   'email'        => '[email protected]',
 *   'sub'          => '1234567890',
 *   'iat'          => 1516239022,
 *   'exp'          => 1516243210
 * ]
 */
bash
composer