?
Solved

disabled cookes request cookie and null cookie values

Posted on 2007-03-20
13
Medium Priority
?
627 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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