473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Eternal Debate: Cookies vs. Sessions vs. QueryString

Here is a question that should get everyone going.

I have an ecommerce site where I need to pass the order_id to every page. So
which method is the best practice to pass this variable between pages:
Cookies or Session variable or by the HTTP header (either GET querystring or
POST form)?

I do not like to use sessions because they time out after 20 minutes of
inactivity.

I do not like to use cookies because the user can disable the use of cookies
through their browser setttings.

I am not big on the querystring/form method but it looks like it might be
the safest way to ensure the app will not break.

Is there a document which talks about the best practice to do this?

TIA.
Dec 9 '05 #1
6 6420

Paul wrote:
Here is a question that should get everyone going.

I have an ecommerce site where I need to pass the order_id to every page. So
which method is the best practice to pass this variable between pages:
Cookies or Session variable or by the HTTP header (either GET querystring or
POST form)?

I do not like to use sessions because they time out after 20 minutes of
inactivity.

I do not like to use cookies because the user can disable the use of cookies
through their browser setttings.

I am not big on the querystring/form method but it looks like it might be
the safest way to ensure the app will not break.

Is there a document which talks about the best practice to do this?

TIA.


Dec 9 '05 #2
Paul have a look at this (it is from the 3schools site)
http://www.w3schools.com/asp/asp_cookies.asp

It might be the answer you are looking for?
What if a Browser Does NOT Support Cookies?
---------------------------------------------------------------------
If your application deals with browsers that do not support cookies,
you will have to use other methods to pass information from one page to
another in your application. There are two ways of doing this:

1. Add parameters to a URL
You can add parameters to a URL:

<a href="welcome.asp?fname=John&lname=Smith">
Go to Welcome Page</a>

And retrieve the values in the "welcome.asp" file like this:

<%
fname=Request.querystring("fname")
lname=Request.querystring("lname")
response.write("<p>Hello " & fname & " " & lname & "!</p>")
response.write("<p>Welcome to my Web site!</p>")
%>

2. Use a form
You can use a form. The form passes the user input to "welcome.asp"
when the user clicks on the Submit button:

<form method="post" action="welcome.asp">
First Name: <input type="text" name="fname" value="">
Last Name: <input type="text" name="lname" value="">
<input type="submit" value="Submit">
</form>

Retrieve the values in the "welcome.asp" file like this:

<%
fname=Request.form("fname")
lname=Request.form("lname")
response.write("<p>Hello " & fname & " " & lname & "!</p>")
response.write("<p>Welcome to my Web site!</p>")
%>

Dec 9 '05 #3
Hi Paul,

Passing an order_id to every page could be a problem, as a hacker could use
the order_id to perform various types of nefarious operations, depending
upon how well you defend your app. Cookies can be a problem. Even Session
Cookies can be a problem, but most browsers allow Session Cookies. I would
recommend using Session, as it keeps all the private data on the server.
Just make sure and account for a timed-out Session.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Here is a question that should get everyone going.

I have an ecommerce site where I need to pass the order_id to every page.
So
which method is the best practice to pass this variable between pages:
Cookies or Session variable or by the HTTP header (either GET querystring
or
POST form)?

I do not like to use sessions because they time out after 20 minutes of
inactivity.

I do not like to use cookies because the user can disable the use of
cookies
through their browser setttings.

I am not big on the querystring/form method but it looks like it might be
the safest way to ensure the app will not break.

Is there a document which talks about the best practice to do this?

TIA.

Dec 9 '05 #4
Hi Kevin,

If it is in web farm, can session be retrieved in different machine?

Thanks,
Elton Wang

"Kevin Spencer" wrote:
Hi Paul,

Passing an order_id to every page could be a problem, as a hacker could use
the order_id to perform various types of nefarious operations, depending
upon how well you defend your app. Cookies can be a problem. Even Session
Cookies can be a problem, but most browsers allow Session Cookies. I would
recommend using Session, as it keeps all the private data on the server.
Just make sure and account for a timed-out Session.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Here is a question that should get everyone going.

I have an ecommerce site where I need to pass the order_id to every page.
So
which method is the best practice to pass this variable between pages:
Cookies or Session variable or by the HTTP header (either GET querystring
or
POST form)?

I do not like to use sessions because they time out after 20 minutes of
inactivity.

I do not like to use cookies because the user can disable the use of
cookies
through their browser setttings.

I am not big on the querystring/form method but it looks like it might be
the safest way to ensure the app will not break.

Is there a document which talks about the best practice to do this?

TIA.


Dec 9 '05 #5
Why are cookies a problem?

When you say "Make sure you account for a timed-out session", what do you
mean? If I store the variable in a session variable, and the session times
out, then I lose the order. Even if I do a check to see if the session timed
out, it still means that the order will be invalid because I will have lost
order id?

I like session variables also but I have a problem with the timeout.

I think cookies are the best solution, why do you think they are a problem?

"Kevin Spencer" wrote:
Hi Paul,

Passing an order_id to every page could be a problem, as a hacker could use
the order_id to perform various types of nefarious operations, depending
upon how well you defend your app. Cookies can be a problem. Even Session
Cookies can be a problem, but most browsers allow Session Cookies. I would
recommend using Session, as it keeps all the private data on the server.
Just make sure and account for a timed-out Session.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Here is a question that should get everyone going.

I have an ecommerce site where I need to pass the order_id to every page.
So
which method is the best practice to pass this variable between pages:
Cookies or Session variable or by the HTTP header (either GET querystring
or
POST form)?

I do not like to use sessions because they time out after 20 minutes of
inactivity.

I do not like to use cookies because the user can disable the use of
cookies
through their browser setttings.

I am not big on the querystring/form method but it looks like it might be
the safest way to ensure the app will not break.

Is there a document which talks about the best practice to do this?

TIA.


Dec 12 '05 #6
Hello Paul ,
Cookies are a problem in this situation because they have a size limit ( to
be exact 4096 bytes wich means that you can store a string of 255
characters max )

you can extend the session timeout if you feel that 20 minutes inactivity
( =default ) is to short to close the session

what i also do in my programs is storing info in hidden form fields

see this website for an example how session vars would work
http://www.bildelskatalogen.se/ ( swedish ,, but it is pretty clear )
regards

Michel Posseth [MCP]

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Why are cookies a problem?

When you say "Make sure you account for a timed-out session", what do you
mean? If I store the variable in a session variable, and the session times
out, then I lose the order. Even if I do a check to see if the session
timed
out, it still means that the order will be invalid because I will have
lost
order id?

I like session variables also but I have a problem with the timeout.

I think cookies are the best solution, why do you think they are a
problem?

"Kevin Spencer" wrote:
Hi Paul,

Passing an order_id to every page could be a problem, as a hacker could
use
the order_id to perform various types of nefarious operations, depending
upon how well you defend your app. Cookies can be a problem. Even Session
Cookies can be a problem, but most browsers allow Session Cookies. I
would
recommend using Session, as it keeps all the private data on the server.
Just make sure and account for a timed-out Session.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
> Here is a question that should get everyone going.
>
> I have an ecommerce site where I need to pass the order_id to every
> page.
> So
> which method is the best practice to pass this variable between pages:
> Cookies or Session variable or by the HTTP header (either GET
> querystring
> or
> POST form)?
>
> I do not like to use sessions because they time out after 20 minutes of
> inactivity.
>
> I do not like to use cookies because the user can disable the use of
> cookies
> through their browser setttings.
>
> I am not big on the querystring/form method but it looks like it might
> be
> the safest way to ensure the app will not break.
>
> Is there a document which talks about the best practice to do this?
>
> TIA.


Dec 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
<?php class LoginSessionGenerator { /** * Logout * * @access public */ function &logout() { // STATIC VOID METHOD
13
by: G | last post by:
Hello, Is it possible to send form values from PAGE1 to PAGE2, and then retain the form info for PAGE3 without using cookies, sessions or DB storage? Also, I dont want to repost page2 to page3...
2
by: | last post by:
Its strange...I have experimenting with browser hawk by using the cookie sniffer method. However, even If adjust the security slider level in internet options or goto advanced in the privacy tab I...
0
by: Sri. | last post by:
Hi I am trying to figure out how to test whether my browser cookies are enabled. I used the code from the following page...
0
by: Sri | last post by:
Hi I am trying to figure out how to test whether my browser cookies are enabled. I used the code from the following page...
1
by: Thomas Scheiderich | last post by:
Just when you figure out one problem another one shows up. I am trying to set up authentication for one of my folders and can't seem to get it to work as advertised (I am sure I am missing...
1
by: ken.prat | last post by:
Given the following: <script>document.cookie = "foo=cookie;";</script> <form action="form.aspx?foo=query" method="post"> <input name="foo" type="hidden" value="fom" /> <input type="submit" />...
26
by: Bookham Measures | last post by:
Hello We are planning to set-up a load balanced web environment. Accordingly, we are going to change the session management on our website from the classic ASP Session State and session...
41
by: amygdala | last post by:
Hello all, I have posted a similar question in comp.lang.php in the past, but haven't had any response to it then. I kinda swept the problem under the rug since then. But I would really like to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.