Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,158 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,940 people online right now. Registration is fast and FREE... Join Now!




just need a little advice with sessions

 
Reply to this topicStart new topic

just need a little advice with sessions

didgy58
31 Dec, 2007 - 02:50 AM
Post #1

D.I.C Head
**

Joined: 23 Oct, 2007
Posts: 170



Thanked: 1 times
My Contributions
hi guys just want to pick ur brains again

ive created a login system on my site using sessions. which as a normal login system searches a database for the user if they are present it then starts the sessions $_SESSION['name'] and $_SESSION['user_id'];

on my shopping cart i start a session called cart which contains the product id, quantity, product name and cost. as well as this it contains the total and a few other calculations..

now i havent in any way linked these two together as of yet and this is what im trying to get my head around really

when the user logs in and then they go to browse my products they have aleady started a session, so could i link the session cart to this session, and if so how would you go about this,, the main reason for really doing this is i was thinking of having a save feature in the cart much like amazon do where the user logs in and then can save the cart to a database called temp orders which then contains there id,product id etc, when they login again i could do a simple query to check they are logged in and there id and then check the database and then if so add there saved items to the correct section of the cart.

do you guys think that this might be a complicated task or with what i already have in place shouldnt be that difficult


thanks
User is offlineProfile CardPM
+Quote Post

dontKnowJava
RE: Just Need A Little Advice With Sessions
31 Dec, 2007 - 08:54 AM
Post #2

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
sounds pretty simple. dont start another session for the cart. just use the same one as login and add whatever extra you want to save to your db. id add product ids and quantities and have the calculations done dynamically.
User is offlineProfile CardPM
+Quote Post

darklighter
RE: Just Need A Little Advice With Sessions
5 Jan, 2008 - 08:12 AM
Post #3

New D.I.C Head
*

Joined: 5 Jan, 2008
Posts: 18


My Contributions
Remember to add the user's id to the table where you store the product information so when the user logs back in you can just their $_SESSION['user_id'] to pull their product data from the table.

And yea, you can just keep all the product data in the same session, just put it all in an array and then just create a new session var and put the array in it like so:

$_SESSION['product_data'] = $arraywithproductinfo;

~Darklighter

User is offlineProfile CardPM
+Quote Post

didgy58
RE: Just Need A Little Advice With Sessions
8 Jan, 2008 - 02:33 AM
Post #4

D.I.C Head
**

Joined: 23 Oct, 2007
Posts: 170



Thanked: 1 times
My Contributions
so by that do you mean using a persisten shopping cart, because right now, my cart if inactive for a certain amount of time will just lose its goods, but if i add a new table to my database called saved products and then in the code, add a save function in the cart, or is it possible to do a function that when the session is about to expire and the user is logged in it automatically saves the information into the cart as i think this would be a nicer touch??

and then in the new database hold the customer id and the product ids of the and quantity of each product they have, and then recall that in a section of the shopping cart which i could call saved cart??

does this make much sense?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 11:41PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month