PHP code example of firebase / token-generator

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

    

firebase / token-generator example snippets


use Firebase\Token\TokenException;
use Firebase\Token\TokenGenerator;

try {
    $generator = new TokenGenerator('<YOUR_FIREBASE_SECRET>');
    $token = $generator
        ->setData(array('uid' => 'exampleID'))
        ->create();
} catch (TokenException $e) {
    echo "Error: ".$e->getMessage();
}

echo $token;

use Firebase\Token\TokenGenerator;

$generator = new TokenGenerator('<YOUR_FIREBASE_SECRET>');

// Using setOption()
$token = $generator
    ->setOption('admin', true)
    ->setOption('debug', true)
    ->setData(array('uid' => 'exampleID'))
    ->create();

// Using setOptions()
$token = $generator
    ->setOptions(array(
        'admin' => true,
        'debug' => true
    ))
    ->setData(array('uid' => 'exampleID'))
    ->create();