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!
Hey guys, if you've ever visited phphelp.com you may know me. PHP forums have gone down for some bizzar reason so I was suggested to come here .
Anyway, I'm developing a shopping basket problem is I cant seem to enter the product id into an multidimentional session.. for instance...
$_SESSION['basket']['item_2'] = 3;
will return 1, infact what ever number I put in seems to return as 1.. I've checked the code and it accepts pure chatares so I could write "bleh" and it would return "bleh", but if I wrote "bleh3" it would return "1bleh"...
I think I figured it out, it has something to do with mutiple dimention sesions...
I had a 4 dimentioned session... when I made that a fith dimention it seemed to limit the charaters it could handle..
I suspect PHP has allocated the whole session string a certain size, once you use up that space it cuts off the remaining code.
Now I've dropped the dimentions to 3, 4 at most. It works fine, but I suspect if I tried to add much more data to the highest dimnetion it would cull it.
true, sessions do have an upper limit to their size. I'd suggest storing that data in a database, or figuring out how to minimize the space requirements. In order to see the actual size of your session data, use [php_man]serialize()[/php_man] on it like so:
I know for a fact, multidimensional arrays use a lot of extra bytes when stored.
You may want to consider creating your own session data handler, so you can compress the data or use other packing methods to minimize the size. Alternately, you can use a database to store the information.
I think this was mentioned earlier but you might want to create a cart table in the database and store everything that is being ordered in it.
When doing something with ordering, I like to store the cart in the database. That way if a customer is ordering something and fills out their person information but drops out before the credit card or confirmation page, you can attach the cart to that customer. Then if they don't purchase the product in a week or so, you can send them an email asking them if there was a problem.
There's a lot of other good reasons for storing the cart in the database also.
Yeah I had thought about using a database for the cart system, but there are many problems agianst using it. Such as the build up of useless data.
Once the user confirms they want that stuff it can be converted to a quote which is saved in the database.
I guess it'll be one of those things I'll have to wait and see. The modularization of ths suite should allow me to make tha changed should I need to...
Thanks for the info though, gave me a few ideas there
Its not so much that, but sessions are so insainly easy and easily solve any stoage, connection or security issues which can be an issue with databases.
To get the cart working on simple sessions only requires at most 5 lines of code...