session too small to use to store serialized class |
[eluser]jared4444[/eluser]
My plan was to serialize a class and stuff it in a session variable, then unserialize it. It seems to be too big. If I serialize a string, or array I can put it in the session, but when I try something that is too big, it just seems to ignore the command and still contains the old session variable. I have serialized the class, and printed it to the string so I know that it did exist, but it was around 10000 characters. Is there a better way to do this? $newordercookie = serialize($this->itemsordered); $this->session->set_userdata('sessionorder', $newordercookie); If I print out $newordercookie, it exists. I can also save and recall a string like "test" and the session stuff works. What should I do?
[eluser]Sean Gates[/eluser]
Are you using a database to store the session? If not, you should consider it, because it stores the data in a "text" type field, which means you have a lot more space. http://ellislab.com/codeigniter/user-gui...sions.html I think the max for a session cookie is 4096 characters, but that is before you add the session wrapper info.
[eluser]bretticus[/eluser]
IE conforms to the minimum RFC recommendations: * at least 300 cookies * at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header) * at least 20 cookies per unique host or domain name Of course you can get around storing session data in a cookie by using the database as Sean suggests. Also, you can use real PHP sessions if you don't want to store this data in the database, although, I think the database is your best bet.
[eluser]jared4444[/eluser]
Thanks for the advice, I might check out the database option. I thought about it and I really only need a relatively small array, there is no need to serialize a model when I really care about a few fields. This actually brings up a good point. I like the model approach to code igniter and this is my first real application. I have been filling a models by passing id into a get statement and the model will fill (hydrate) itself. I find myself always wanting to set presets to fields so I initialize everything at the top. I do have some functionality in a class that I inherit from which extends model my_model, but I think it is pretty standard. I think that the way that I am filling my model and associated model might be an overkill and that I am making things more complicated than they need to be. I was hoping some people could take a look at my code. Specifically the way I get an item along with its associated sizes and prices in a different model. I have a base model class that I also will include along with item_model and Sizemapping_model. I hope that someone might be able to tell me if this is overkill. I am very new and this question makes me thing I should be doing a lot more with arrays. My database for shopping cart item (id, name, description) ie. shirt, pants, socks size(id, name, description) ie. small, medium, large item_to_size_mapping(id, item_id, size_id, price) Basically I have items and each item can have many sizes. Each item/size combination has a price. so: item.name, size.name, item_to_size_mapping.price Shirt, Small, $50 Pants, Large, $75 Please look at the way that I am populating the item menu where I list items by a category. item_model.getItemsAndMappingsCategoryID this populates an array of its own model, each of these has an array of another model Thanks! I really need to get an opinion. |
Welcome Guest, Not a member yet? Register Sign In |