PHP - website e-commerce, generate UUID for each shopping cart

Asked

Viewed 54 times

0

Good morning, first of all, I’m trying to create a unique code for each shopping cart, which is the best way, I was thinking of using UUID, but I have no idea how to do it, if anyone knows a good forum that talks about it they’re willing to thank you ;)

  • coincidence.. is almost related to this: http://answall.com/questions/80604/qual%C3%A9-a-l%C3%B3gica-de-um-carrinho-de-compras-de-compras

1 answer

0


Something simple and functional is to use timestamp information

$token = microtime();

Something like this will come back

0.13287600 1460718460

If you do not want the space character you can generate as well:

$token = microtime(true);

Will return something like: 1460718491.9867

Of course, if this uuid/token is publicly accessible, it is recommended to encrypt it at least to prevent anyone from understanding how the token is generated. In this example, using timestamp any programmer can guess that the format is a timestamp and with that can make a token hijacking. So if you use a very obvious sequence, encrypt it.

$token = hash('sha256', microtime(true));
//gera algo como `6d20018cf7023becaf77a2e0dc5d4034894aebdde9febb093f83dbcc3744bce0`

Browser other questions tagged

You are not signed in. Login or sign up in order to post.