If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Rochester, NY
    Member #
    I am using an md5 hash as the primary key, for storing session data on an e-commerce site. The site is written in ASP but we are using a mySQL backend. The code is pretty self explanatory, (') is the single line comment for ASP(if you are unfamiliar).
    CSTR() is convert to string, CINT() is convert to int.

    Basically the problem is as follows. Once or twice a day I get a key insert collision. I don't know why, since theoretically there are 2^128 keys availible and average number of rows in the database is about 300.

    Any ideas ?

    Thanks In Advance.

    	randomNumber = CINT(1000 * Rnd())
            'cat our data together into a string
    	s = CSTR(timeStamp) + CSTR(ipAddress) + CSTR(randomNumber)
    	'generate md5 Hash
    	sDigest = md5(s)
    	'insert into Cart DB
    	SET sessionStorer = SERVER.CREATEOBJECT("ADODB.Connection")  
    	sessionStorer.Open Application("globalCartDBConnectionSTR")
    	insertSQL = "INSERT INTO `carts` ( `sessionIdSTR` , `sessionTIME` , `drIdSTR` , `referrerSTR` , `keywordSTR` ) " & VbCrLf &_
    				"VALUES ( " & VbCrLf &_
    				"'" & sDigest & "', NOW( ) , '" & Application("globalDrIdSTR") & "', '" & referrer & "', '" & keyword & "' );"
            'This code here makes sure there aren't any carts that havent been touched in the last 20 minutes bloating our database
    	deleteSQL = "DELETE  FROM  `carts`  WHERE (" & VbCrLf &_
    				"sessionTIME < DATE_SUB( NOW(  ) ,  INTERVAL  '0:40' HOUR_MINUTE  )" & VbCrLf &_
    	'send those poor abandoned souls, like your name was Yuna.			
    michael murphy
    Professional Web Development


  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Member #
    Don't know how critical they are to you, but I know some fairly complex randomizers in PHP.

    As you are using VB, I don't know how random "rand()" would be in that language. In PHP you add some additional randomizers to the initial rand().
    If it's not death critical, you could utilize the auto-increment function of mysql and use it as an augumenter for your your unique key. (it would be predictable though, if you're a high profile decoder on a military payrole, but for general use it would be random enough)
    S. Rosland

  4. #3
    Senior Member
    Join Date
    Aug 2003
    Member #
    Your problem is MOST likely to be due to proxy servers. If you have a certain group of users using the same proxy server, their remote IP will be identical even when they're different users. It happens in corporate settings and with some ISPs.

    One way around it is to check for the HTTP_X_FORWARDED_FOR header. This should be set by all self-respecting servers and it will be a space-delimited list of IP addresses starting with the proxy's address till the final user's actual IP address. Usually, there are only two addresses (the proxy's and the user's) but if there are more, then there are multiple proxies along the way.

    So to sum up:

    1. Check if there is a proxy header - use that if so.
    2. If not use the IP address.

    I also suggest using a proper randomiser. Also, are you 'seeding' the random number generator? Most need to be seeded with a unique value (usually the current time stamp) before being used to generate a random number otherwise you have a high chance of getting the same 'random' number many times. I can't remember how the ASP/VB one works. Read up on that.

    Hope this helps.
    eKstreme - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.

  5. #4
    Join Date
    May 2005
    Rochester, NY
    Member #
    ekstreme and rosland,
    Thank you both for your input. I'll try a better method of randomizing and research the proxy server issue. Thanks again.
    michael murphy
    Professional Web Development

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search tags for this page

md5 hash primary key

md5 primary key
Click on a term to search for related topics.
All times are GMT -6. The time now is 11:28 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: