469,282 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

How to detect if cookies are enabled?

Hi,
I searched around everywhere on the net, but could not find a simple example
of detecting if cookies are enabled - on server side, and without moving
from one page to another.
This should be a very basic functionality, so I am reluctant to believe that
there's no way to simply test it in a server-side script.
Anyone?

Thx,
Agoston
Jul 22 '05 #1
9 7656
AFAIK no. You have to test this client side (it could be on the same page
depending on what exactly annoys you with client side methods).

Patrice

--

"Agoston Bejo" <gu***@freemail.hu> a écrit dans le message de
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,
I searched around everywhere on the net, but could not find a simple example of detecting if cookies are enabled - on server side, and without moving
from one page to another.
This should be a very basic functionality, so I am reluctant to believe that there's no way to simply test it in a server-side script.
Anyone?

Thx,
Agoston

Jul 22 '05 #2
"Agoston Bejo" <gu***@freemail.hu> wrote in message
news:#H**************@TK2MSFTNGP10.phx.gbl...
Hi,
I searched around everywhere on the net, but could not find a simple example of detecting if cookies are enabled - on server side, and without moving
from one page to another.
This should be a very basic functionality, so I am reluctant to believe that there's no way to simply test it in a server-side script.
Anyone?

Thx,
Agoston


"... detecting if cookies are enabled - on server side ..."

Are you asking how to detect if client-side cookies are enabled via
server-side ASP?
"Response.Cookies" is defined as "A collection containing the values of all
the cookies that will be sent back to the client in the current response.".

"Request.Cookies" is defined as A collection of the values of all the
cookies sent from the user's system along with their request."

Thus, I thought that this would work:

Response.Cookies("aCookie") = "Hello World"
Response.Write "Are client-side cookies enabled? = " & (Not
IsEmpty(Request.Cookies("aCookie")))

But it returned "True" even when Cookies were disabled.
Jul 22 '05 #3
McKirahan wrote on 10 feb 2005 in
microsoft.public.inetserver.asp.general:
detecting if cookies are enabled - on server side,
and without moving from one page to another.
But that is a silly expectation.
Thus, I thought that this would work:

Response.Cookies("aCookie") = "Hello World"
Response.Write "Are client-side cookies enabled? = " & (Not
IsEmpty(Request.Cookies("aCookie")))

But it returned "True" even when Cookies were disabled.


How do you expect the server knowing anything about the client,
without contacting the client?

You will have to resort to something like this:

1.asp:

<%
Response.Cookies("aCookie") = "Hello World"
Response.redirect "2.asp"
%>

2.asp:

<%
If Session("aCookie") = "Hello World" Then
Response.Write "Cookies Enabled"
Else
Response.Write "Cookies Disabled"
End If
%>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #4
The problem is that it works as a request/response pairs.

The client sends a request and you respond to this request. If you write
down cookies to the response, it will make them visible in the *next*
request, not in the request you respond to.
You'll have to use something similar to what Evertjan shows (there is a
typo, this Cookies not Session).

You could do it on the same page if this is really a problem with some query
string to know at which step you are...

Patrice

--

"McKirahan" <Ne**@McKirahan.com> a écrit dans le message de
news:bO********************@comcast.com...
"Agoston Bejo" <gu***@freemail.hu> wrote in message
news:#H**************@TK2MSFTNGP10.phx.gbl...
Hi,
I searched around everywhere on the net, but could not find a simple example
of detecting if cookies are enabled - on server side, and without moving
from one page to another.
This should be a very basic functionality, so I am reluctant to believe

that
there's no way to simply test it in a server-side script.
Anyone?

Thx,
Agoston


"... detecting if cookies are enabled - on server side ..."

Are you asking how to detect if client-side cookies are enabled via
server-side ASP?
"Response.Cookies" is defined as "A collection containing the values of

all the cookies that will be sent back to the client in the current response.".
"Request.Cookies" is defined as A collection of the values of all the
cookies sent from the user's system along with their request."

Thus, I thought that this would work:

Response.Cookies("aCookie") = "Hello World"
Response.Write "Are client-side cookies enabled? = " & (Not
IsEmpty(Request.Cookies("aCookie")))

But it returned "True" even when Cookies were disabled.

Jul 22 '05 #5
[...]
detecting if cookies are enabled - on server side,
and without moving from one page to another.
But that is a silly expectation.

[...] How do you expect the server knowing anything about the client,
without contacting the client?


Request.ServerVariables("HTTP_USER_AGENT")
By using this, you definitely get some information about the client on
server side. So I don't think that expectation is so silly. I accept that
about cookies you cannot get information this way, however.

Thanks anyway!

Jul 22 '05 #6
Agoston Bejo wrote on 12 feb 2005 in
microsoft.public.inetserver.asp.general:
[...]
> detecting if cookies are enabled - on server side,
> and without moving from one page to another.


But that is a silly expectation.

[...]
How do you expect the server knowing anything about the client,
without contacting the client?


Request.ServerVariables("HTTP_USER_AGENT")
By using this, you definitely get some information about the client on
server side. So I don't think that expectation is so silly. I accept
that about cookies you cannot get information this way, however.

Thanks anyway!


The HTTP_USER_AGENT value is sent with the request,
as are available cookie values tagged to the server domain.

So you could test for those cookie values, but if absent,
the difference between no cookies available and cookies switched off
cannot be detected without testing for it on the client as shown.

Yes, the powers that defined the cookie mechanism could have defined and
required a cookies-switched-off flag in the page request sent by the
browser, but they did not.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #7

What annoys me is that first I have to detect if JavaScript is enabled in
order to be able to test whether cookies are enabled.

Agoston

"Patrice" <no****@nowhere.com> wrote in message
news:eX**************@TK2MSFTNGP10.phx.gbl...
AFAIK no. You have to test this client side (it could be on the same page
depending on what exactly annoys you with client side methods).

Patrice

--

"Agoston Bejo" <gu***@freemail.hu> a écrit dans le message de
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,
I searched around everywhere on the net, but could not find a simple

example
of detecting if cookies are enabled - on server side, and without moving
from one page to another.
This should be a very basic functionality, so I am reluctant to believe

that
there's no way to simply test it in a server-side script.
Anyone?

Thx,
Agoston


Jul 22 '05 #8
You don't need JavaScript. See Evertjan response in this thread...

Patrice
--

"Agoston Bejo" <gu***@freemail.hu> a écrit dans le message de
news:%2***************@TK2MSFTNGP15.phx.gbl...

What annoys me is that first I have to detect if JavaScript is enabled in
order to be able to test whether cookies are enabled.

Agoston

"Patrice" <no****@nowhere.com> wrote in message
news:eX**************@TK2MSFTNGP10.phx.gbl...
AFAIK no. You have to test this client side (it could be on the same page depending on what exactly annoys you with client side methods).

Patrice

--

"Agoston Bejo" <gu***@freemail.hu> a écrit dans le message de
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,
I searched around everywhere on the net, but could not find a simple

example
of detecting if cookies are enabled - on server side, and without moving from one page to another.
This should be a very basic functionality, so I am reluctant to
believe that
there's no way to simply test it in a server-side script.
Anyone?

Thx,
Agoston



Jul 22 '05 #9
Evertjan. (before drinking his coffee) wrote:
<snipped>
You will have to resort to something like this:
1.asp:
<%
Response.Cookies("aCookie") = "Hello World"
Response.redirect "2.asp"
%>

2.asp:
<%
If Session("aCookie") = "Hello World" Then ^^^^^^^^^^^^^^^^^^
Request.Cookies("aCookie") Response.Write "Cookies Enabled"
Else
Response.Write "Cookies Disabled"
End If
%>

Jul 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sri. | last post: by
reply views Thread by Sri | last post: by
6 posts views Thread by NWx | last post: by
2 posts views Thread by Tee | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.