Jump to content

Passing a value through sessions?


xgd

Recommended Posts

Hello,

I am making a shopping cart, and basically i got stuck.  I do not know how to pass the value of the $total variable (which contains the order total) from view_cart.php to the checkout.php page so i can store it in a database.

 

Can someone please help me with that ?

 

I get the $total like this:

	$subtotal = $_SESSION['cart'][$row['print_id']]['quantity'] * $_SESSION['cart'][$row['print_id']]['price'];
	$total += $subtotal;

 

So how do i know pass that $total variable to another page (in this case checkout.php) so i can freely use it ?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/195557-passing-a-value-through-sessions/
Share on other sites

Simple answer, you dont need to. You cart contents are already contained within a session. Simply write a simple function that gives you the cart total that you can call on any page. Loop through the cart items price and times by the quantity. There is your total. You have already posted part of the code.

Sessions persist throught a script (as long as you have called session_start()) until they are destroyed i.e You will destroy the shopping cart session after the user has paid for their items.

 

You would never send prices, totals, etc through the url. This can be easily manipulated and users could end up paying nothing for the items in their cart.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.