Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie problem

Status
Not open for further replies.

Beracosta

Programmer
Oct 25, 2000
47
0
0
SE
Hi! I have a big problem. I want to check if a visitor of my page already has been there. And i want to do that by checking if the cookie "knife" is empty or not. I have tried the following command:

if Request.Cookies("knife") == "" then

else

...... lots of code here....

end if

Can anyone help me?
 
Try displaying the value of Request.Cookies("knife")
IF it is equal to nothing try using the <> (not equal) check for some reason this works
sometimes when checking if they are equal (==) and using else doesn't.

Walter III

Walt III
SAElukewl@netscape.net
 
your code is like vbscript , so follow the james's advice.
Jim
 
nothing of the above works. I already have tried it and nnow i tried it again. doesn't work! pls help me!!!
Björn
 
are you actually getting the value of the cookie back or is that what you are trying to do. I am not sure I understand where your problem lies.

walter III

Walt III
SAElukewl@netscape.net
 
i should also say that it is VBScript that i'm jusing. Im sorry for the '=='. I just made a mistyping in the hurry =)
 
Ok. What i want to do is to check if the visitor has been on my site before, and if he has the code for that goes on, and if i hasn't, the code for that goes on.

so by checking if the cookie is there i can see if i has been on my page. And if he hasn't been on my site, the page will make some other things like setting the cookie.

Do u understand or am i very bad att explaining =). it's hard to explain in a other language than my native =)

Thanx for the help btw...

/Björn
 
You might want to check to see if the person has been in the If statement and then put the code for if he hasn't in the else. This will only work if the people have a consistant value for a key in the cookie.
Does your cookie have multiple key/value pairs?

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
No. Tha cookie just contains a unic ID. like &quot;38DSGVSXSD...&quot;
So if there is a cookie that contains a id, do this, else do that. Do u understand? pls help me
 
Ah, I wish I would have read this earlier ... this is an easy one to fix ... Try this ...

[tt]
If Request.Cookies(&quot;knife&quot;).HasKeys Then
** code to execute if cookie exists **
Else
** code to execute if there isn't a cookie **
End If

** code to execute when you're done and are ready to go home and have a beer ** =D
[/tt]

I hope this helps, if not, then check the cookie settings in the browser you're testing with and make sure cookies are not disabled. I know this works for sure since at my job we wanted to show the FAQ of our site the very FIRST time anyone visited a site (or any PC for that matter) and it worked like a champ. FAQ never popped up as long as I didn't clear the cookies or jump to another PC.

I hope this helps. =) Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
it doesn't work win .HasKeys. When i do that, the page takes it like if there wasn't a cookie. grrrr. how should i do?
 
I'm wondering if the root of your problem is where you're writing the cookie ... could you show the code where the cookie is being written? Perhaps it's expiring instantly. Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
OK. Here is the code where the cookie is being set: Response.Cookies(&quot;kockkniv&quot;) = IDNum

/Björn
 
Ok, that looks right of course, I just wanted to be sure you didn't set an invalid expiration value with it as well.
Just to be safe, you might want to hard code the expiration such as:

[tt]Response.Cookies(&quot;kockkniv&quot;).Expires = Date + 30[/tt]

Hmm ... what else could I recommend ...

Looks like your cookie isn't being set at all, are you setting this cookie in the headers of your page? If I remember correctly, you just can't set a cookie in the middle of a page because the headers have already been sent. You must set the cookie inside your
Code:
<HEAD></HEAD>
tags. Double check the location of your cookie code and insure that it is within the header tags, or else, the cookie just won't get created. Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
I know this is kind of obvious but it sometimes gets missed, the simple things usually do - are cookies allowed by the client browser?
It will never work if this is the case. Check the security settings of the browser.

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
I know that the cookie is beening set because when i display the value of the cookie with Response.Write Request.Cookies(&quot;knife&quot;) it shows the correct value, and it also shows the correct and the same value when i update the browser. But if i close the browser and then opens it again, the cookie gets a new value. how should i solve this!!!


/Björn

&quot;I really, really hate computers and of course COOKIES!!!!&quot;

:D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top