Skip to content

Instantly share code, notes, and snippets.

@thedineshj
Last active October 28, 2018 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedineshj/7fbc12ad8f40568167af1c472aeba52b to your computer and use it in GitHub Desktop.
Save thedineshj/7fbc12ad8f40568167af1c472aeba52b to your computer and use it in GitHub Desktop.
using json web tokens with php
<?php
require './php-jwt/BeforeValidException.php';
require './php-jwt/ExpiredException.php';
require './php-jwt/JWT.php';
require './php-jwt/SignatureInvalidException.php';
use \Firebase\JWT\JWT;
$data=[
"profileId"=>12345678,
"createdOn"=>time()
];
$key="secretkey";
// json web token
$jwt=JWT::encode($data,$key);
echo $jwt;
echo "<br />";
// decoding json web token
$decodedJwt=JWT::decode($jwt,$key,array('HS256'));
print_r(((array)$decodedJwt));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment