Can you tell us the book you're using? It doesn't seem to be one of the standards or someone would have recognised it.
If there's no suggestion at all the the person using this rather simple Shopping Cart script has bought something and set a cookie before, it could still make sense in a way.
It doesn't need a previous cookie to work. It doesn't say
after all.#retrieving cookie @purchases = split(/ /, cookie('cookie')) || die "No cookie!";
You'll just end up with an array with zero elements. Onto which will be pushed whatever you just bought.
Perhaps it should say
at that point, if that's the intention?#retrieving cookie if there is one
Anyway. Why would you get a cookie, then turn around right away and set one?
This is an example of a shopping cart, which is a frequently-used metaphor in online shopping. If you go to Amazon or any other online shopping place, what happens? You click to buy a book, and, is the process over at that point? No. You're not asked for your credit card yet. You may choose other books, in the same way as you may use a real shopping cart and select a number of real-life items then go to the checkout.
The imaginary situation is that you've selected some items already, and by using the form, you've added another one to that list of items. Use the form again, and you add another item. Use the form a hundred times and you add a hundred items, and they are all recorded in the cookie.
The weirdness is, it's OK for you to have selected no items yet, the script is intended to work starting from zero items, or any higher number.
That's why you get and set. You get the cookie which says "he has already bought one thing", you add to it and send back a cookie saying "now he has bought two things" and so on.
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
In reply to Re: Question regarding CGI and cookies
by Cody Pendant
in thread Question regarding CGI and cookies
by JOT007
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |