php - what are the cons of using unix timestamp as an order ID? -
i designing shopping project , thinking using unix timestamp order id. know can use mysql incremental numbers use order id 10001, 10002, etc. don't want know how many orders there are.
is safe way it? don't expect more 1 order per second, should safe, right?
function check_number(){ $unique_number = time(); $exists = $this->count_rows('orders', "where order_id='" . $unique_number . "'"); if ($exists >0){ $results = check_number(); } else{ $results = $unique_number; return $results; } }
a more robust solution use php's uniqid() function. hides number of orders in system, wont go belly-up if 2 or more orders happen come in @ same second.
as actual question: no, it's not safe use unix timestamps unique ids semi-random events, users making orders. unlikely may be, why leave in possibility of collision when can avoided?
Comments
Post a Comment