Link to home
Start Free TrialLog in
Avatar of thatelvis
thatelvis

asked on

disabled cookes request cookie and null cookie values

Hello,
I have 2 questions on implementing what I need done. am greatful for help/ input.

Q1.
<% If  Request.Cookies("countrylong") = "" Then  %>

with this if statement above, what happens when there is no cookie there, how will it validate, Am I correct in thinking that I will also need to add a if isnull like below.

<% If isnull(Request.Cookies("countrylong")) = ture OR Request.Cookies("countrylong") = "" Then  %>

I am totally confused as to wheather it would need to be validated against null or not.

-------------------------------------------------

Q2. the code below.
I am running an if or,  if the cookie value is nothing or the cookie is not there then run this script.
<%
If isnull(Request.Cookies("countrylong")) = ture OR Request.Cookies("countrylong") = "" Then  %>
<!--#include file="my_ssis/country_check.asp" -->
<% ' cookie location finish
 End If %>

the contents of the include my_ssis/country_check.asp is below

<%
'  Set A Cookie To Value of countrylong
Response.Cookies("countrylong") = ("")
'if conditions are not met below then we get the deault value above =("Internationally ")
If not RecCountry.eof  then
if NOT isNull(RecCountry.Fields.Item("countrylong").Value) then
     if (RecCountry.Fields.Item("countrylong").Value) > ""  Then    
          Response.Cookies("countrylong") =(RecCountry.Fields.Item("countrylong").Value)
          Response.Cookies("countrylong").Expires = Date + 28
          Response.Cookies("name").Domain = ""
          Response.Cookies("name").Path = "/"
          Response.Cookies("name").Secure = true
    End If
End If
End If
  %>

My problem here is when I test this in firefox etc, I have cookies turned off and all my cache is clear. but this code runs . what I am really confused about is, when I have this on my page, <%=cStr(Request.Cookies("countrylong"))%> it gets populated. how can it get populated when the persons cookies are turned off. I had beleive if some one does not have cooies turned on then they will not work.

can any one help me and explain as to what might not be working.

Regards

Kenny
Avatar of Si_Hibbard
Si_Hibbard
Flag of United States of America image

Q1)
VBscript - you do not need to check if null here, just check if it is empty

// If cookie is not empty
if Request.Cookies("countrylong") <> "" Then  
Q2)

Not sure about firefox but how are you disabling cookies in IE?
Are you just disabling third party cookies but running this on a trusted (or local) server for example?
Avatar of thatelvis
thatelvis

ASKER

I really only used the firefox one at present as it was easier to disable enable cookies.  firefox have a plugin for developers that make easy work of disableing enabling things see tutorial here
http://tips.webdesign10.com/web-developer-toolbar.htm
see firefox plugin here
http://chrispederick.com/work/webdeveloper/

regards

k


well basically if a browser does have cookies disabled properly and you really have cleared the cookie associated with the sites domain your code will not load anything from it.

I can only assume that the tool is not working as you expect, i.e. not clearing the cookie already set or properly disabling them.

I would remove the code that creates the cookie from your page.
Manually check the cookie has been deleted.
Disable cookies, close and re-open the browser and try you page again, the value should not be loaded.

Hello,
I have done as you mentioned, I removed the cookie, and manually checked that it has been deleted etc
etc but when I return to the same page with the if statement it does show the value of the cookie.
I do not have a link to my site at present only the code sorry.

I am begining to wonder
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/conwinner.asp" -->
<%
'Start cookie location start
' if they have the cookie then no need to re qeuery the countries database
If Request.Cookies("countrylong") = "" Then  %>
<!--#include file="my_ssis/country_check.asp" -->
<% ' cookie location finish
 End If %>
could the above  be validating against a server cookie.  if so I dont remember creating one.

this is the country ssi

<%
'  Set A Cookie To Value of countrylong
Response.Cookies("countrylong") = ("")
'if conditions are not met below then we get the deault value above =("Internationally ")
If not RecCountry.eof  then
if NOT isNull(RecCountry.Fields.Item("countrylong").Value) then
     if (RecCountry.Fields.Item("countrylong").Value) > ""  Then    
          Response.Cookies("countrylong") =(RecCountry.Fields.Item("countrylong").Value)
          Response.Cookies("countrylong").Expires = Date + 28
          Response.Cookies("name").Domain = ""
          Response.Cookies("name").Path = "/"
          Response.Cookies("name").Secure = true
    End If
End If
End If
  %>



change the check to this

If Request.Cookies("countrylong") = "" Then  
response.write("cookie empty")
else
response.write("cookie exists")
end if

I just want to find out if when you say "it does show the value of the cookie" that is really the case
Hi Again and thank you. I tried what you mentioned but added to it

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
If Request.Cookies("countrylong") = "" Then  
<!--#include file="my_ssis/ztest1.asp" -->
else
<!--#include file="my_ssis/ztest2.asp" -->
end if
 %>
 <%
If Request.Cookies("countrylong") = "" Then  
response.write("cookie empty and not using ssi")
else
response.write("cookie exists and not using ssi")
end if
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

When no cookie  my out put  is          cookie exists and not using ssi .

When yes  cookie  my out put  is       cookie exists and not using ssi

I get no out put from the if else using the ssi.

regards

kenny

okay something very odd seems to be going on.

basck to basics - write a basic page that simply sets a cookie and writes some value to it.

disable cookies in your browser, load the page, then manually check - does the cookie get created?
Thanks Si,
I have created this page below. I have cookies disabled in IE, I have cleared my cache and cookies etc. then I viewed the page only to be confrounted with all the content on the page. I check my cookies but none in the cookie dir.


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
if ("" = "")  then
  myExpire = DateAdd("d", 30, Now())
  cookieName = "testcookie1"
  Response.Cookies(cookieName) = "this is the cookie value hello"
  Response.Cookies(cookieName).Expires = myExpire
  Response.Cookies(cookieName).Path = "/"
  if ("" <> "") then
    Response.Cookies(cookieName).Domain = ""
  end if
  Response.Cookies(cookieName).Secure = 0
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<p><%=cStr(Request.Cookies("testcookie1"))%></p>
<p>&nbsp;</p>
<p>this is a show hide, if cookie is not empty then show<br>
  <br>
  <% If (cStr(Request.Cookies("testcookie1"))) <> ("") Then 'Start ta cokie test %>
    hello welcome the cookie exists
    <% End If 'End ta cokie test %></p>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of Si_Hibbard
Si_Hibbard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi yea,
I tried it on two computers
I viewed page 1 and I opened page 2
and got "No Cookies"

I refreshed the pages a gew times but that didnt do anything.

I then went to the code and changed the 2001 to 2009. and then got "Cookies"

I am very confused and grateful for any help

Kenny
Si Come ere,
i managed it and reliaise what the problem was.

See when I was setting the cookie

<%
'  Set A Cookie To Value of countrylong
Response.Cookies("countrylong") = ("")

there is a value in "" even though no space but it was kicking in, I cant believe it myself. any way.

this is what I ended up ding in my if else and it works a treat.

<%
If (isnull(Request.Cookies("countrylong"))) = false Then  %>
<!--#include file="my_ssiss/country_check.asp" -->
<%  End If %>

it is checking for the exsistance of the cookie correct, but the cooke would not bethere had it not already been created, and it was created when I was setting the thing with "", so silly me HA, any way,

thank you very much and I feel today was very successful

regards

kenny




Hi Kenny,

Sorry I couldnt get back to you yesterday, but looks like you finally got there thats great well done :)

Si//