PHP code example of xaamin / jwt

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

    

xaamin / jwt example snippets


	$payload = [
			'sub'   => 1,
			'username' => 'xaamin'
	    ];

	// Generate token
	$token = Xaamin\JWT\Facade\Native\JWT::encode($payload);

	// Verify the token
	try{
		$token = Xaamin\JWT\Facade\Native\JWT::decode($token->get());

	    var_dump($token);
	} catch (Exception $e) {
		echo $e->getMessage();
	}

	$payload = [
			'sub'   => 1,
			'username' => 'xaamin'
	    ];

	// Generate token
	$token = Xaamin\JWT\Facade\Native\JWT::encode($payload);

	// Verify the token
	try{
		$token = Xaamin\JWT\Facade\Native\JWT::decode($token->get());

	    var_dump($token);
	} catch (Exception $e) {
		echo $e->getMessage();
	}