Skip to content

Instantly share code, notes, and snippets.

@kerstner
kerstner / gist:252c0346a3f52f6d8252
Last active May 10, 2016 13:17
Generate 6 Character Random Bit.ly like ID for a URL with PHP and MySQL
// Set number of shortcodes to generate
$shortcodes = 10000000;
// Loop through and create unique shortcodes
while ($shortcodes) {
$shortcode = generateShortcode();
$checkSQL = "SELECT shortcode FROM shortcodes WHERE shortcode = '" . $shortcode . "'";
$checkResult = $mysqli->query($checkSQL);
// If doesn't exist, insert into database