Solved

unique ID cookie for shopping cart

Posted on 2000-04-07
8
300 Views
Last Modified: 2013-12-25
I'm in the process of finishing a mySQL backed e-commerce site, and will be implementing a shopping cart. The best way I've thought to do this would be to give every user a cookie with a unique ID number. Then everytime they place something in their cart, a record is added to the database with thier unique ID as the key.

I'm unsure of how to go about assigning this unique ID cookie, though. I know how to set and retrieve cookies, and process their info. But how would I set the cookie in the first place? Would I need an SSI call to set the cookie?

Also, how can I generate the unique ID? And how can I make sure that this cookie is secure (not SSL), so that their unique ID will not change over the course of their visit to the site?

I'm not interested much in the code needed to accomplish this, but rather the logistics involved. I appreciate any help, and will generously reward those who can help...

-Mike King
0
Comment
Question by:lunaboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 1

Expert Comment

by:mafweb
ID: 2693906
hi Mike,

would be interesting to know which language you're using. PHP, for example, gives you the possibility to create an unique id with
uniqid()  (have a look at http://www.php3.de/manual/function.uniqid.php3).

Besides, what you can do to create such a token is to take the current time in milliseconds and concatenate it with some random value. This should be good enough (I know, there is slight a very slight chance that this is not unique *sigh*, but I don't know any other solution)

hope this helps,
maf
0
 
LVL 1

Expert Comment

by:mafweb
ID: 2693918
by the way, you don't necessarily need SSI to set the cookie, all you need is the possiblity to send the cookie string before the end of the HTTP-header, especially before any HTML content

maf
0
 
LVL 1

Author Comment

by:lunaboy
ID: 2694048
Thanks for the tip...

How would I set the cookie string before the end of the HTTP-header if the document is the index.shtml of the domain?

ex/ http://www.domain.com/index.shtml

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 8

Expert Comment

by:jhurst
ID: 2694861
the milliseconds and random is not a good approach - those 'tiny windows' always come back and haunt you.  And the worst thing about that one is that it only starts to hurt when you system starts to get lots of hits and is sucessful.

The general method of making a guaranteed unique number is language non-specific.  Open a file in which you keep a count, lock it, increment the count, unlock the file and use the count as the next sequence number.
0
 
LVL 1

Expert Comment

by:mafweb
ID: 2694959
that depends on the language. in php3, you just say

<?php
setcookie ("cookie_name", "cookie_val", time()+$expire);

in the first line of your page.
For Perl, this is similar, only that it does not provide an own setcookie function

maf
0
 
LVL 1

Author Comment

by:lunaboy
ID: 2695215
okay, I have set the cookie as
uniqueID=<IP ADDRESS><RANDOM NUMBER>

That should work fine. This isn't a high traffic site, and we won't be getting so many users from the same IP at the same time ;-)

But, I'm using Perl and mySQL as a database (which is irrelavent to this quesiton), the front page is an .shtml doc, parsed by SSI of course. The problem I am having is that I want EVERY visitor to the site to get the cookie on the first page they visit, no matter where they enter. If there a way to make sure apache sends the set-cookie statement in every header? How can I do this?

Or how else could I ensure that every person gets a cookie?

-Mike K.
0
 
LVL 1

Accepted Solution

by:
mafweb earned 100 total points
ID: 2695739
I don't know whether you can configure apache like that, but if you have a logo displayed on that page, you could write a little perl script like this (let's hope your visitors have images on):

#!/path/perl
print ""; #cookie-code here, look at netscape's site for details
print "location:yourlogo.gif";

and insert it with
<img src=cookie.pl alt=logo>

this will set the cookie and display your logo. As said, can only be used, if your visitors have their images setting to "show"

maf
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2697103
Apache does allow you to send the header first from your cgi.  I can not believe that there would be any server that would not allow this.  The header needs to go and as part of this is the content type, cachece control, cookies, etc.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

E-commerce is quite a gambling world, and you should never entrust your business to a lucky chance. In order to outrun your competitors in a race to attract as many customers as possible, you need to have a well thought-out strategy under your belt.…
Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question