How to detect if cookies are enabled?
Question posted by: Agoston Bejo
(Guest)
on
July 22nd, 2005 02:27 AM
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
9
Answers Posted
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" <gusz1@freemail.hu> a écrit dans le message de
news:%23HytiF3DFHA.3856@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi,
> I searched around everywhere on the net, but could not find a simple[/color]
example[color=blue]
> 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[/color]
that[color=blue]
> there's no way to simply test it in a server-side script.
> Anyone?
>
> Thx,
> Agoston
>
>[/color]
"Agoston Bejo" <gusz1@freemail.hu> wrote in message
news:#HytiF3DFHA.3856@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi,
> I searched around everywhere on the net, but could not find a simple[/color]
example[color=blue]
> 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[/color]
that[color=blue]
> there's no way to simply test it in a server-side script.
> Anyone?
>
> Thx,
> Agoston
>[/color]
"... 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.
McKirahan wrote on 10 feb 2005 in
microsoft.public.inetserver.asp.general:
[color=blue]
> detecting if cookies are enabled - on server side,
> and without moving from one page to another.[/color]
But that is a silly expectation.
[color=blue]
> 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.
>[/color]
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)
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" <News@McKirahan.com> a écrit dans le message de
news:bOCdnePqPPc_-pbfRVn-pg@comcast.com...[color=blue]
> "Agoston Bejo" <gusz1@freemail.hu> wrote in message
> news:#HytiF3DFHA.3856@TK2MSFTNGP10.phx.gbl...[color=green]
> > Hi,
> > I searched around everywhere on the net, but could not find a simple[/color]
> example[color=green]
> > 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[/color]
> that[color=green]
> > there's no way to simply test it in a server-side script.
> > Anyone?
> >
> > Thx,
> > Agoston
> >[/color]
>
> "... 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[/color]
all[color=blue]
> the cookies that will be sent back to the client in the current[/color]
response.".[color=blue]
>
> "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.
>
>[/color]
[...][color=blue][color=green]
> > detecting if cookies are enabled - on server side,
> > and without moving from one page to another.[/color]
>
> But that is a silly expectation.
>[/color]
[...][color=blue]
> How do you expect the server knowing anything about the client,
> without contacting the client?[/color]
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!
Agoston Bejo wrote on 12 feb 2005 in
microsoft.public.inetserver.asp.general:
[color=blue]
> [...][color=green][color=darkred]
>> > detecting if cookies are enabled - on server side,
>> > and without moving from one page to another.[/color]
>>
>> But that is a silly expectation.
>>[/color]
> [...][color=green]
>> How do you expect the server knowing anything about the client,
>> without contacting the client?[/color]
>
> 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![/color]
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)
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" <nobody@nowhere.com> wrote in message
news:eXZQEQ3DFHA.3824@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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" <gusz1@freemail.hu> a écrit dans le message de
> news:%23HytiF3DFHA.3856@TK2MSFTNGP10.phx.gbl...[color=green]
> > Hi,
> > I searched around everywhere on the net, but could not find a simple[/color]
> example[color=green]
> > 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[/color]
> that[color=green]
> > there's no way to simply test it in a server-side script.
> > Anyone?
> >
> > Thx,
> > Agoston
> >
> >[/color]
>
>[/color]
You don't need JavaScript. See Evertjan response in this thread...
Patrice
--
"Agoston Bejo" <gusz1@freemail.hu> a écrit dans le message de
news:%236c3EkUEFHA.560@TK2MSFTNGP15.phx.gbl...[color=blue]
>
> 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" <nobody@nowhere.com> wrote in message
> news:eXZQEQ3DFHA.3824@TK2MSFTNGP10.phx.gbl...[color=green]
> > AFAIK no. You have to test this client side (it could be on the same[/color][/color]
page[color=blue][color=green]
> > depending on what exactly annoys you with client side methods).
> >
> > Patrice
> >
> > --
> >
> > "Agoston Bejo" <gusz1@freemail.hu> a écrit dans le message de
> > news:%23HytiF3DFHA.3856@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > Hi,
> > > I searched around everywhere on the net, but could not find a simple[/color]
> > example[color=darkred]
> > > of detecting if cookies are enabled - on server side, and without[/color][/color][/color]
moving[color=blue][color=green][color=darkred]
> > > from one page to another.
> > > This should be a very basic functionality, so I am reluctant to[/color][/color][/color]
believe[color=blue][color=green]
> > that[color=darkred]
> > > there's no way to simply test it in a server-side script.
> > > Anyone?
> > >
> > > Thx,
> > > Agoston
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]
Evertjan. (before drinking his coffee) wrote:
<snipped>[color=blue]
> 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[/color]
^^^^^^^^^^^^^^^^^^
Request.Cookies("aCookie")[color=blue]
> Response.Write "Cookies Enabled"
> Else
> Response.Write "Cookies Disabled"
> End If
> %>[/color]
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 197,003 network members.
Top Community Contributors
|