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

0

Good day first, I'm trying to create a unique code for each shopping cart, what better way, I was thinking of using UUID, but I have no idea how to do it, if anyone knows one good forum that talks about it is at will thanks;)

    
asked by anonymous 15.04.2016 / 12:22

1 answer

0

Something simple and functional is to use timestamp information

$token = microtime();

It will return something like this

0.13287600 1460718460

If you do not want the space character then you can also generate:

$token = microtime(true);

Return something like: 1460718491.9867

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

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