vinpkl Posted June 1, 2015 Share Posted June 1, 2015 Hi How can i create a client id which is 64 bit integer as described on this below link https://developers.google.com/analytics/devguides/collection/protocol/v1/email#client-id-cid thanks Vineet Quote Link to comment https://forums.phpfreaks.com/topic/296588-how-to-create-64-bit-client-id/ Share on other sites More sharing options...
dalecosp Posted June 1, 2015 Share Posted June 1, 2015 (edited) Well, here is an *easy* way. $client_id = openssl_random_pseudo_bytes( 64 ); Not sure it's the *best* way Edited June 1, 2015 by dalecosp Quote Link to comment https://forums.phpfreaks.com/topic/296588-how-to-create-64-bit-client-id/#findComment-1513004 Share on other sites More sharing options...
gizmola Posted June 2, 2015 Share Posted June 2, 2015 You can consider this method. Just keep in mind that before you assign this to a user you have to check for collision. Even if the chances are minuscule, there is always the possibility that you'll have generated this number previously. <?php // seed with microseconds function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } mt_srand(make_seed()); for ($i=0; $i < 25; $i++) { $id = mt_rand() . '.' . mt_rand(); echo $id . "\n"; } You'll get this: 1430510990.211800510 1466558525.1174334161 505344300.1022366902 1102498041.512780900 2021435785.822065269 1067052107.2031154900 1573696108.839071663 1980123314.867137495 2084311793.1584365915 1003446906.1472857995 315507374.1484330943 142579337.206780113 1981674287.967067949 463749784.1337826872 332981579.604370553 815957892.954609975 1162600210.642213439 1685383521.1211289722 266829926.1463632230 59693777.670718427 1738677010.1526829074 1863209293.1713778803 1540998699.2715544 1268514048.212413847 1070525702.1303096993 Based on php's implementation of the Mersenne Twister algorithm. Quote Link to comment https://forums.phpfreaks.com/topic/296588-how-to-create-64-bit-client-id/#findComment-1513015 Share on other sites More sharing options...
vinpkl Posted June 2, 2015 Author Share Posted June 2, 2015 Hi Gizmola thanks for this solution. if worked for me thanks vineet Quote Link to comment https://forums.phpfreaks.com/topic/296588-how-to-create-64-bit-client-id/#findComment-1513017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.