PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I want to set a session variable that has an array in it to a cookie, and then everytime a page is loaded update the cookie with new information. And if the session is killed for some reason, I want the cookie to be read and reset the session value. I have this so far....
I am looking at the cookies in FireFox, and I am getting different cookie values for the info for different directories, when they all should be the same. Should I be doing after the isset($_S... line a check and if cookie $_COOKIE... = $_SESSION... and if not set cookie?
Last edited by tecktalkcm0391 on Tue Jun 19, 2007 10:15 pm, edited 1 time in total.
I'm curious as to why you would store data in a cookie that's effectively dependent on another cookie (the session), when you have full control over both.
I want to store a cookie that lasts, because the information is for a shopping cart, and I want the cart to remain active, but if the user is logged-in it still logs them out after the session expires (browser closes)
Ok, but the visitor doesn't have to have an account. Example: officedepot.com you go to there website. you can add stuff to your shopping cart, login, and out, exit the browser, and open it again and your shopping cart stays. thats what I am trying to accomplish.
Ok, I narrowed it down to something with serialize and unserialize not working right. Any ideas? Testing some codes, I'll see if I can figure out why, but help would be greatly appreciated.
feyd wrote:Why not save their cart to a set of (database) tables?
I was thinking about that, but how would it just reappear when then come back if its in 6 hours.
You could use the cookie only to store the id of their cart in the database (and maybe another value for verification.. a "password" if you will), and then access their cart from that. No serialization would have to be done at all in this case.
It's a string? Don't store that in a cookie. The size of cookies is severely limited. Use the database. Set their session cookie to have an expiration then use that as the key (in some form) to the database records.