Skip to content
A simple PHP library to encode/decode + sign JWT-Tokens
PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
JWT.php
LICENSE
README.md

README.md

PHP-JWT

This class implements a simple way to en-/decode JWT-Tokens

Usage

require_once '/path/to/JWT.php';

$jwt = new JWT('secret');

$token = $jwt->encode([
  "name" => "Max Mustermann",
  "nbf" => time() + 120       // Valid in 2 minutes
]);

try{
  $payload = $jwt->decode($token);
  
  print_r($payload);
}catch(Exception $e){
  if($e instanceof JWTException){
    echo "The token is not valid";
  }
}

Exception-Classes

JWTException

MalformedException extends JWTException

The token has a wrong format

SignatureInvalidException extends JWTException

The token's signature is wrong

ExpiredException extends JWTException

The token has expired

BeforeValidException extends JWTException

The token is not yet valid

You can’t perform that action at this time.