PHP code example of jinpy666 / jwt
1. Go to this page and download the library: Download jinpy666/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/ */
jinpy666 / jwt example snippets
// Secret password
$key = '1234';
// Claimset
$claimSet = array(
// user id
'iss' => '1',
// Expiration Time
'exp' => strtotime(date('Y-m-d H:i:s') . ' + 1 day')
);
$jwt = new \Jinpy666\Jwt\JsonWebToken();
// Create token
$token = $jwt->encode($claimSet, $key);
// check token
$claimDecoded = $jwt->decode($token, $key);
if($claimDecoded['valid'] == true) {
echo 'Token is valid';
} else {
echo 'Error: Token is not valid';
}