Skip to content

Instantly share code, notes, and snippets.

@ZahidRasheed
Last active April 22, 2021 15:05
Show Gist options
  • Save ZahidRasheed/ec08e9fcebe3671cbb3f4d8a2e7109da to your computer and use it in GitHub Desktop.
Save ZahidRasheed/ec08e9fcebe3671cbb3f4d8a2e7109da to your computer and use it in GitHub Desktop.
<?php
function getFallbackToken()
{
$date = new DateTime();
$date->add(new DateInterval('PT4H'));
echo $date->format('Y-m-d H:i:s');
$expires = $date->format(DateTime::ATOM);
$content = json_encode([
'expires' => $expires,
'ip' => "127.0.0.1",
'userid' => rand(10000, 99999),
]);
$cipher = new AES(AES::MODE_ECB);
$cipher->setKey(env('FALLBACK_AES_KEY', 'RandomStringMadeFrom32Characters'));
$token = base64_encode($cipher->encrypt($content));
$res = array(
'token' => $token,
'expires' => $expires,
);
return $res;
}
getFallbackToken();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment