Register and join over 40,000 other developers!
Recent Topics
-
Tekken 7
IsrealJones - Mar 22 2021 07:21 AM
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

5 replies to this topic
#1
Posted 18 October 2009 - 07:10 AM
Hi,
I'm programming a shopping cart with php but i'm not sure if it's better to use session or database to save the items in the cart (cart is a class in my code). What do you advise me? Maybe the sessions are better because a guest can also put his items in his cart...
Thanks in advance... bye...^^
I'm programming a shopping cart with php but i'm not sure if it's better to use session or database to save the items in the cart (cart is a class in my code). What do you advise me? Maybe the sessions are better because a guest can also put his items in his cart...
Thanks in advance... bye...^^
#2
Posted 18 October 2009 - 10:21 AM
I would store data in the database. Sessions will still be important, however, for managing the database access.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
My MineCraft server site: http://banishedwings.enjin.com/
#3
Posted 18 October 2009 - 11:15 AM
This is my actual Cart:
I think that the sessions are more convenient because a guest can fill the cart while he is unregistered.. What do you think?
class Cart
{
private $items;
public function __construct()
{
if(!isset($_SESSION['items']))
$this->items = array();
else
$this->items = $_SESSION['items'];
}
public function __destruct()
{
$_SESSION['items'] = $this->items;
}
public function add_item($id, $num)
{
if($num > 0)
$this->items[$id] += $num;
else
$this->items[$id] = 0;
}
public function show_items()
{
return $this->items;
}
}
I think that the sessions are more convenient because a guest can fill the cart while he is unregistered.. What do you think?
#4
Posted 18 October 2009 - 01:04 PM
To check out, I would still want the person to be registered.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
My MineCraft server site: http://banishedwings.enjin.com/
#5
Posted 18 October 2009 - 01:06 PM
You could always make it session only if the user isn't logged in, and database-based otherwise. I assume they need to register at some point though to purchase something, at that point you can throw it into a database from the session variables.
If you're selling stuff online; it's always good to have records!
Well, that's what I would do.
If you're selling stuff online; it's always good to have records!
Well, that's what I would do.
#6
Posted 18 October 2009 - 01:10 PM
I could be wrong, but I think a properly designed database would be easier on the server than loads of session variables per user.
Also tagged with one or more of these keywords: session
General Forums →
Mobile Development →
html5 web storage session loginStarted by mutago, 11 May 2014 ![]() |
|
![]() |
||
Language Forums →
PHP →
PHP Session VS. Session issetStarted by Serialcek, 31 Jan 2014 ![]() |
|
![]() |
||
General Forums →
General Programming →
Preventing Session Hijacking?Started by Pally, 20 Dec 2013 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Passing PHP session variables to a Jquery/Ajax script.Started by elliottveares, 15 Oct 2013 ![]() |
|
![]() |
||
![]() PHP session set but not being detectedStarted by JakeWelton, 06 Oct 2013 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download