I am learning to set up a cookie and assign a user_Id to whoever visits my website. I want to keep a record of all user IDs in mySQL database. I tried something like this:
if(!isset($HTTP_COOKIE_VARS['user_id']))
{ $cart_id = md5(uniqid(rand()));
$COOKIE=setcookie("cart_id", $user_id, time() + 14400);
if (!$COOKIE)
{
echo "To complete your order your browser must be set to accept cookies";
}
}
else
{
$user_id = $HTTP_COOKIE_VARS['user_id'];
}
I believe the results I got did not seem to be convincing because verytime I refreshed my browser, the value of the user_id changed. Then I tried this
session_start();
$user_id=session_id();
which I believe also did not work well.
For both methods, whenver I tried to save the $user_id variable in mySQL database, the string was always truncated even after increasing the field width to 250.
Any ideas on these two linked problems are highly appreciated.