Skip to content

A little PHP util to generate and validate JSON Web Tokens (JWTs)

Notifications You must be signed in to change notification settings

chtgupta/PHP-JWT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

PHP-JWT

A little PHP util to generate and validate JSON Web Tokens (JWTs)

Generate token

require 'jwt.php';
  
$payload = array(
  'id' => '1001',
  'email' => 'chahat@hexoncode.com');
        
$expiry = time() + (3 * 3600);
$secret = 'somesecretkey';
        
$token = generate_token($payload, $expiry, $secret);
echo $token;

Validate token

This function simply validates the JWT and returns a response code based on signature and expiry time. See Response codes for details.

$result = validate_token($token, $secret);
echo $result;

Validate token and get payload data post successful validation

This function validates the JWT and returns the payload array in case of successful validation. Returns a response code otherwise. See Response codes for details.

$result = validate_token_with_payload($token, $secret);
echo $result;

Response codes

Response Reason
ERR_TOKEN_EXPIRED Token has expired
ERR_TOKEN_INVALID Token is invalid (signature didn't match)
TOKEN_VALID Token is valid and active

About

A little PHP util to generate and validate JSON Web Tokens (JWTs)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages