PHP code example of alexpts / php-jwt-service

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

    

alexpts / php-jwt-service example snippets



use Emarref\Jwt\Algorithm\Hs512;
use PTS\JwtService\JwtService;

$secret = 'sa#FD423efdl#';
$alg = new Hs512($secret);

$service = new JwtService($alg);
$jwtToken = $service->encode(['userId' => 1]);

// with auto expire
$service->setExpire(3600);
$jwtToken2 = $service->encode(['userId' => 1]);


$jwtToken3 = 'some string jst token';
$tokenObject = $service->decode($jwtToken3);