I am building an e-commerce website using PHP, mysql, javascript.
My idea is to save one token, say a 50 character guid, to a single cookie, and use this to identify the user for each request.
I would then save other items such as cart_id, order_id, customer_id, logged_in (bool) and expires_at in a sessions table of the database.
I would probably then refresh the token upon each corresponding request and renew it's expiry time.
I'd like to know if this would be considered a secure way of maintaining a session, and if it's generally a good idea.
Also, anything else I can do to make a logged in session more secure would be a bonus. Thanks.
Edit:
This is the function I'm using to generate my guid:
<?php
function guid($length) {
$bytes = ceil($length/2);
$guid = bin2hex(openssl_random_pseudo_bytes($bytes));
return $guid;
}
I'm calling it as follows:
<?php
$token = guid(50);