Solved

disabled cookes request cookie and null cookie values

Posted on 2007-03-20
13
589 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:thatelvis
  • 7
  • 6
13 Comments
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18754895
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  
0
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18754927
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?
0
 
LVL 1

Author Comment

by:thatelvis
ID: 18754968
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


0
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18755042
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.

0
 
LVL 1

Author Comment

by:thatelvis
ID: 18755315
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
  %>



0
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18755430
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
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:thatelvis
ID: 18755508
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

0
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18756378
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?
0
 
LVL 1

Author Comment

by:thatelvis
ID: 18756601
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>
0
 
LVL 10

Accepted Solution

by:
Si_Hibbard earned 500 total points
ID: 18757572
okay simplyfy the code first, lets make sure the system is working. if this works as expected there must be a problem with your code. unfortunatly i am at work otherwise i would try your code for myself.

page1:
<%
Response.Cookies("ClientID") = "test"
Response.Cookies("ClientID").Expires = "December 31, 2001"
%>

page2:
<%
testCookie = Request.Cookies("ClientID")

If testCookie = "" Then
   response.write("No Cookies")
else
  response.write("Cookies!!")
End If

-----
load up page 1, then 2.

you can then try this with enabled/disbaled setting (ensure to remove cookie file before running second time)
0
 
LVL 1

Author Comment

by:thatelvis
ID: 18758558
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
0
 
LVL 1

Author Comment

by:thatelvis
ID: 18758966
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




0
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18762601
Hi Kenny,

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

Si//

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now