Sessions or Cookies, Arrays or Dictionary Objects?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Sessions or Cookies, Arrays or Dictionary Objects?

Hybrid View

  1. #1
    T. Bradley Dean Guest

    Sessions or Cookies, Arrays or Dictionary Objects?

    I've written a simple shopping cart to hold domain names and lengths (years)
    for a domain registration site. I've done it with Arrays and Sessions, but
    now after reading many articles on sessions I feel so guilty!

    Would cookies be a better plan? How would I store an array in a cookie?
    Would a Dictionary Object be a better idea?

    Here is my code right now:

    Dim i ' A Counter
    Dim arrCart(50,1) ' The Cart Array
    Dim iCart ' Tells How Many Items In Cart
    (UBound(arrCart) always = 50)

    For i = 0 to iCart
    arrCart(i,0) = Session("arrCart(" & i & ",0)")
    arrCart(i,1) = Session("arrCart(" & i & ",1)")
    Next
    ---------------------------------------------------------
    Is there an easier way to do this? I have a felling that if I do this with
    cookies, it will create a cookie for each item in the cart which would limit
    the amount of items to 20 for many users.

    Any help would be REALLY appreciated!

    Thanks so much,

    Bradley Dean




  2. #2
    daniel Guest

    Re: Sessions or Cookies, Arrays or Dictionary Objects?


    One really sorry way to do this is to use server side code to create x number
    of hidden text boxes within a form and fill these boxes with your data. if
    you name these boxes according to there place in the array then you can access
    these variables on the next page.

    Another way is to append this info to the end of the query string. This way
    when the user browses to the next page all you information will be in the
    query string.

    Should you find a better solution besides using Sessions, Cookies, or creating
    you own Session state db and maintaining them through a dll or something
    I would like to know how. I am investegating using XML to pass this type
    of information but no luck so far.


    "T. Bradley Dean" <Bradley.Dean@InfoDish.com> wrote:
    >I've written a simple shopping cart to hold domain names and lengths (years)
    >for a domain registration site. I've done it with Arrays and Sessions, but
    >now after reading many articles on sessions I feel so guilty!
    >
    >Would cookies be a better plan? How would I store an array in a cookie?
    >Would a Dictionary Object be a better idea?
    >
    >Here is my code right now:
    >
    > Dim i ' A Counter
    > Dim arrCart(50,1) ' The Cart Array
    > Dim iCart ' Tells How Many Items In Cart
    >(UBound(arrCart) always = 50)
    >
    > For i = 0 to iCart
    > arrCart(i,0) = Session("arrCart(" & i & ",0)")
    > arrCart(i,1) = Session("arrCart(" & i & ",1)")
    > Next
    >---------------------------------------------------------
    >Is there an easier way to do this? I have a felling that if I do this with
    >cookies, it will create a cookie for each item in the cart which would limit
    >the amount of items to 20 for many users.
    >
    >Any help would be REALLY appreciated!
    >
    >Thanks so much,
    >
    >Bradley Dean
    >
    >
    >



  3. #3
    Tim Askerov Guest

    Re: Sessions or Cookies, Arrays or Dictionary Objects?


    I am not sure I understand why you would want to copy the array from the Session
    variable to a local variable element by element when you can do that in one
    statement:

    arrCart = Session("arrCart")

    And there's really nothing wrong with using Session to store arrays. What
    you don't want to store in Session or Application variables is any kind of
    external objects, such as ADO, Dictionary object or any custom-built components
    written in VB. That's only because those objects are not multi-threaded,
    and storing them in Session or Application variables locks your server-side
    process down to a single thread, which affects its performance. However,
    arrays are a different thing altogether -- they are a VBScript's native data
    type and don't cause any ASP performance problems.

    Tim

  4. #4
    Bard dZen Guest

    Re: Sessions or Cookies, Arrays or Dictionary Objects?

    Remember also that storing ANYTHING in session, application, or server=20=

    limits your application's scalability and robustness to a single server.=
    =20
    In larger applications that employ clustering, web farms, or load=20
    balancing, this is a VERY bad idea.

    Since processing is distributed across multiple servers, storing=20
    variables in any of the server side objects won't ensure state since wit=
    h=20
    each visit, the customer may visit a different server with each request.=


    >>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<


    On 5/31/00, 9:29:53 AM, "Tim Askerov" <taskerov@subscribe.com> wrote=20=

    regarding Re: Sessions or Cookies, Arrays or Dictionary Objects?:


    > I am not sure I understand why you would want to copy the array from t=

    he=20
    Session
    > variable to a local variable element by element when you can do that i=

    n=20
    one
    > statement:


    > arrCart =3D Session("arrCart")


    > And there's really nothing wrong with using Session to store arrays. =


    What
    > you don't want to store in Session or Application variables is any kin=

    d=20
    of
    > external objects, such as ADO, Dictionary object or any custom-built=20=


    components
    > written in VB. That's only because those objects are not multi-thread=

    ed,
    > and storing them in Session or Application variables locks your=20

    server-side
    > process down to a single thread, which affects its performance. Howev=

    er,
    > arrays are a different thing altogether -- they are a VBScript's nativ=

    e=20
    data
    > type and don't cause any ASP performance problems.


    > Tim


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center