ARTLUNG LAB Share

From December 2005

Make a Unique ID in PHP

Use random numbers to create some random characters, and then use the time and a unique id to make a unique id. Similar to the way a GUID is created in Windows.

Results

WA1734851187W6767ba734cee6

...And the Source Code:

<?php
// Just a small sample of making a unique id in PHP
// https://www.php.net/manual/en/function.chr.php
// https://www.php.net/manual/en/function.rand.php
// http://www.php.net/manual/en/function.time.php
// http://www.php.net/manual/en/function.uniqid.php

    $prefix = 'W'; // a universal prefix prefix
    $my_random_id = $prefix;
    $my_random_id .= chr(rand(65,90));
    $my_random_id .= time();
    $my_random_id .= uniqid($prefix);
    print $my_random_id;
?>