Skip to content

Instantly share code, notes, and snippets.

@yurimorales
Last active December 10, 2019 20:45
Show Gist options
  • Save yurimorales/af85826851266a245d6c1a457aa1db21 to your computer and use it in GitHub Desktop.
Save yurimorales/af85826851266a245d6c1a457aa1db21 to your computer and use it in GitHub Desktop.
Random Token Generator - PHP
<?php
$generateToken = function($length = 50) {
$token = "";
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$maxNumbers = strlen($string);
$i = 0;
while ($i < $length) {
$token .= $string[ random_int(0, $maxNumbers - 1) ];
$i++;
}
return $token;
};
echo $generateToken(60) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment