Page 1 of 1

Cookies taste awful

Posted: Tue Jul 29, 2003 11:34 am
by chemoautotroph
For some reason whenever I store more than 3 items in a cookie array, it starts deleting old items. Why and how do I fix it??

This is really bad, because I'm using cookies to create a shopping cart, and after 3 items are added, the old ones disappear- I don't think my customer would appreciate that.

Posted: Tue Jul 29, 2003 12:22 pm
by JPlush76
why are you storing shopping cart info in cookies? tis is bad idea. Look into using a database or at least a session array.

I run an ecommerce site and we have many customers who don't enable cookies(they think we're going to cyber attack them lol).

Posted: Tue Jul 29, 2003 1:53 pm
by patrikG
Cookies have a fixed maximum filesize of somthing around 4Kb (or around that value). If you're using PHP, don't use cookies to store data, there are plenty of other ways:
sessions
serialization
database (provided you have access to a database)
etc.

Posted: Tue Jul 29, 2003 2:32 pm
by m3rajk
sessions are tricky. cookies store more than get. get is session's second method, post being the first. cookies being the third.

the database or using a text file are probalby the best way

Posted: Tue Jul 29, 2003 2:35 pm
by nielsene
m3rajk wrote:sessions are tricky. cookies store more than get. get is session's second method, post being the first. cookies being the third.

the database or using a text file are probalby the best way
I wouldn't call sessions tricky.

In the "standard" php install, cookie is the first session method, not the last. Sessions's fall back to GET is the cookie is rejected. POST propagation is only used when a form is detected and is seperate from the GET/Cookie decision.

Posted: Tue Jul 29, 2003 2:50 pm
by m3rajk
that's why i call it tricky. first off it uses three other methods, secondly the book i have lists them the way i listed them, and then there's people and places like php.net that has a different opinion..


still, since get is limited and so are cookies and i know post is, but it's a third one greater than get and i don't know how it compares to cookies, i'd say use a text file for the person if you don't have a db, but kow that if you expand past a few customers on at a time the size of the text file directory will get very large very fast. a db is MUCH better, and you can give an order number as well as user number so someoen can go back an look at their previous orders, etc

Posted: Tue Jul 29, 2003 3:03 pm
by nielsene
m3rajk wrote:that's why i call it tricky. first off it uses three other methods, secondly the book i have lists them the way i listed them, and then there's people and places like php.net that has a different opinion..


still, since get is limited and so are cookies and i know post is, but it's a third one greater than get and i don't know how it compares to cookies, i'd say use a text file for the person if you don't have a db, but kow that if you expand past a few customers on at a time the size of the text file directory will get very large very fast. a db is MUCH better, and you can give an order number as well as user number so someoen can go back an look at their previous orders, etc
Well whatever php.net or zend.com lists should be taken as more authoritative than any third-party book.

The point is that while there is a lot that goes on behind the scenes when using sessions, the developer can "forget" about it most of the time. (Yes the developer should eb aware of it)

Posted: Tue Jul 29, 2003 3:03 pm
by patrikG
Sessions are not tricky.

1. You start the session with "session_start()" at the beginning of the page, you assign a session-variable with $_SESSION["myVariable"]='bla'.
Nothing tricky so far.

2. Now, as Jason states in his sticky, HTTP is a stateless protocol, every page needs to re-register the session with the server. Hence you need session_start() on every page.

3. To identify the session, either a cookie is set on the clients computer containing the session-id, if not, the session-id will be put into the URL via GET.

All a PHP-programmer needs to worry about is step 1 and 2. Step 3 happens automatically.

There is nothing tricky about sessions.

Posted: Tue Jul 29, 2003 6:36 pm
by chemoautotroph
I pretty much figured that $_SESSION was the way to go, I started converting the site over to them before even reading your replies. Thanks anyway.