Echusen Echusen - 3 months ago 10
PHP Question

Random String for transaction code

I would like to ask, I'm developing a website using PHP and currently looking for a better approach.

I want to generate random string for the transaction code.

For example: Customer purchased a product, there must be transaction code to be generated and store it in database table.

Is it better to use a PHP function to generate this then check if transaction code already exists in database table or should I create a stored procedure that will do this? Which do you think is faster?

Answer

You can make use of uniqid in PHP for this

Something like this will do..

<?php
echo "TRANSID-".strtoupper(uniqid()); //Generates a random id every time.

OUTPUT:

TRANSID-528B185A2EC6C

If you are interested in this have a look here

Comments