PHP code example of worldxyj / jwt

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

    

worldxyj / jwt example snippets


use Worldxyj\Jwt;

$jwt = new Jwt('your own secret');

$payload = [
    'name' => 'worldxyj/jwt',
    'des' => '一个简单的JWT库'
];

$tokenDefault = $jwt->getToken($payload);// 默认过期时间1天

$tokenExp = $jwt->getTokenWithExp($payload, 3600 * 24);// 自定义过期时间

$res = $jwt->verifyToken($tokenDefault);// 验证token

if($res['errcode'] == 0){
    $payload = $res['data'];
    echo '验证通过';
}