Cookies taste awful
Moderator: General Moderators
-
chemoautotroph
- Forum Newbie
- Posts: 3
- Joined: Mon May 12, 2003 4:08 pm
Cookies taste awful
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.
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.
I wouldn't call sessions tricky.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
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.
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
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.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
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)
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.
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.
-
chemoautotroph
- Forum Newbie
- Posts: 3
- Joined: Mon May 12, 2003 4:08 pm