?
Solved

unique ID cookie for shopping cart

Posted on 2000-04-07
8
Medium Priority
?
302 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
A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

 
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 200 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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

764 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