Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Not Unique md5(uniqid(rand())

Status
Not open for further replies.

WilliamMute007

Programmer
Sep 30, 2007
116
GB
Hi all,

I wonder if anyone can render a bit of help please. I have a piece of Session code that I have been using for a while now. It seems to work fine on windows sever but on Apache I seem to be having problem. I have the following code

Code:
if(!isset($HTTP_COOKIE_VARS['cart_id'])) {
     $cart_id = md5(uniqid(rand()));
     setcookie("cart_id", $cart_id, time() + 14400);
 } else {
     $cart_id = $HTTP_COOKIE_VARS['cart_id'];
 }

The aim of this code is to start a session with a random unique session ID which is then entered into a cart then later, the value of the cart is then called based on the set session id matching a session id in my cart table.

The problem am having now is that, when the session is sent to the DB Table, each time it seems to be setting a Unique ID within one user session. So basically if a user tries to add 2 Items into the shopping cart within a min interval, that user is being given two different session ID. It looks like the session ID is changing eveery second so mysql never returns any result as my current session never matches a session id on the table.

Any Help please?
Thank you in advance
 
You probably have a newer version of PHP on your new server. $HTTP_COOKIE_VARS is deprecated and the super global $_COOKIE is preferred. See
___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Fantastical John! Thank you... it works like a charm. Am great full for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top