How to create GUID in php – php create GUID

How to create GUID in php – php create GUID

in this post we will show you How to create GUID in php or php GUID create . guid stands for globally distinctive symbol typically wont to produce random distinctive strings in php, produce access token in php. It’s straightforward to come up with or use guid in php.

In php we’ve inbuilt function com_create_guid() to come up with GUID. to be used this we want COM support in php.ini. From PHP 5.4.5, COM and DOTNET isn’t any longer designed into the php core. you have got to feature COM support in php.ini.


uncomment this line from php.ini for this you have got to get rid of semicolon(;) from starting.
For get additional data concerning COM follow manual.

If COM support isn’t enabled you may get fatal error on calling com_create_guid() :
Fatal error:Call to undefined function com_create_guid()

How to create guid in php victimization windows COM :-

// create GUID
$setguid = com_create_guid();
echo $setguid;

If you’re not windows based mostly platform and not have COM use below code for creating GUID in PHP or take away Fatal error:Call to undefined function com_create_guid() manually by functions :-

// create GUID
function createGUID()
if (function_exists('com_create_guid'))
return com_create_guid();
//optional for php 4.2.0 and up.
$set_charid = strtoupper(md5(uniqid(rand(), true)));
$set_hyphen = chr(45);
// "-"
$set_uuid = chr(123)
.substr($set_charid, 0, 8).$set_hyphen
.substr($set_charid, 8, 4).$set_hyphen
.substr($set_charid,12, 4).$set_hyphen
.substr($set_charid,16, 4).$set_hyphen
// "}"
return $set_uuid;

and calling above function to print guid string:-

// create GUID
$new_GUID = createGUID();
echo "GUID :: ".$new_GUID;

For additional data concerning GUID follow official GUID website wherever you discover additional concerning this.
Mostly use of GUID for generating access token, generate distinctive id, generating distinctive string in php. victimization this text a way to produce guid in php you’ll be able to produce a random string for any use to stay distinctive.

Leave a Comment

Your email address will not be published. Required fields are marked *

1  +  8  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US