Cookies for hotcut

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

syntax:

'Set cookie
Response.Cookies("CookieName") = "CookieValue"

'Get cookie
Request.Cookie("CookieName")
'
Example:
'Set the cookie (page 1)
Response.Cookies("LastVisitDate") = Date
Response.Cookies("LastVisitTime") = Time

'Get the cookie (page 2)
Response.Write "Your last visit was "
Response.Cookies("LastVisitDate") = Date
Response.Write " at "
Response.Cookies("LastVisitTime") = Time
Response.Write "."
'

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

Thanks for the qiuck, and good ansver!

I understand the princips of this! I can make it save cookies just as I want it to do!

There is no problems here... allmost at least...

Cant I update a cookie? lets say that I once have defined the cookie witha value called "no" and then the user ansveres the poll, then I want it to change to a value called "yes" (the same cookie)

When I do something like that, it seems like I get an error... Maybe its just me, making a mistake...

Anyway, your ansver helped me a lot further here!

Casper

[Edited by hotcut on 10-22-2000 at 04:59 AM]

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

You should be able to use the same syntax to update a cookie as you do to create it.

try this...

'page 1
Response.cookie("CookieName") = "value1"

'Now go to "C:\windows\temporary internet files\"
' and find the cookie you just set.
'The value for "CookieName" should be "value1"

'page 2
Response.cookie("CookieName") = "value2"

'fint the cookie again.
'the value should now be "value2"
'

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 6 posts

Joined: Oct 2000

For all i know (not much about cookies) i think you need to write in order to display the cookie:

<?php
=Request.cookie("date")
?>

you can write the two fields in the same cookie

Response.Cookie("visit")("date")=date
Response.Cookie("visit")("time")=time

Now to read from the cookie you do this :

The date you visited is

<?php
=Request.Cookie("visit")(date)
?>

The time you visited is
<?php
=Request.Cookie("visit")(time)
?>

Am i wrong ????

The gray wolf from the land of might and magic

They have: 133 posts

Joined: Sep 2000

Hmmm

First of all, you are telling me to write a cookie in 2 ways! one with the ***.cokie and one with ***.cokies !!! I have found out, that the last one, gotta be the right one...

Now, I am staring to think that my problem is, that I am testing it all from my harddrive, so that I cant save cookies that way.. though that I thourght that you could do that from your harddrive... (using PWS, to set up a network server)

Anyway, does any of you know if that is the problem, or if it is just my computer that doesnt like cookies?

Casper

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

sorry for the inconsistancy.. I didn't notice.

I haven't [l;ayed with ASP and PWS on my machine, but I have used PHP on my machine and it was able o create cookies.

Have you turned cookies off on your machine?

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

Hmmm

No, cokkies is actually on, on my computer, so that aint the problem, and I have allso tryed to put it out on the net, and tested it from there.

Ehhmm... I will try to look at webmonkies, and see if I can find a toturial on cookies´...

If you got any other ideas, please tell me... Else I will just try to find a toturial somewhere...

Casper

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

hotcut,

It would help if you could be a little more descriptive than "I'm getting an error"

The examples here have been correct but I'll go over it again, to set a cookie:

Response.Cookies("value") = "Voted"

To retrieve that key value:

Request.Cookies("value")

To reset that key value:

Response.Cookies("value") = "NotVoted"

If you don't supply an expiry date that cookie will only last until the browser is closed. If you want a cookie that remains on the client's hard drive, use the following:

Response.Cookies("value").Expires = "October 25,2000"

If you plan on storing more than one key in the cookie you will have to name them, but if you're only using this to keep track of voting then you don't need more than one key.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 6 posts

Joined: Oct 2000

Hi hotcut

First of all about your question you cant run Asp or other server side language on your harddrive you have to run it on the net (It server side language so the server have to run it)

Second of all thank you you right its cookies not cookie and in your post you wrote cokies maybe its your mistake its COOKIES

The gray wolf from the land of might and magic

They have: 133 posts

Joined: Sep 2000

To Gray Wol:

Ohhh yea, you can run ASP from your harddrive... I actually did tell you that I set it up using PWS wich stands for: Personal Web Server. It is a program, that you can find on your windows 98 (or maybe allso higher versions) cd, undet updates, or something like that, there you install PWS, and you will then be able to set up a webserver, on your intraner. Actually you dont need to have an intranet for that, you just, when installed, write your computers name in the adress bare in the browser, and you are at you website, on your computer! There you can run ASP from, without having to even open up the internet access!!!

Second, The problem isnt the "cokkie(s)"tag, it is something else...

Back to track again...

Peter, I agree, t´hat you are right in that "I am getting an error" isnt sufficient, but I am getting all ASP errors in Danish, so it is a kind of difficouldt for me to translate something like that... Anyway, I can now try to tell you what it says...

Ok, this is a translation of the danish error code, so try to get the best out of it!:

Response-object error 'ASP 0156 : 80004005'

Headererror

/poll/pollproc.asp, line 12

The HTTP-headers is allready beeing written to the client browser. Changes of the HTTP-headers has to be done, before the contents of the page is written.

Ok, that should make a bit sense... I didnt understand what the actual meaning of it is, but hey, maybe you do!

I will write the code, that I am using, to set the cookie now:

The result

<?php
Response
.Cookies("poll1ansvered") = "yes"


dim spq
spq
= Request.Form("spqnummer")
'... and tons of other ASP stuff...
?>

Can you see what the problem posible can be here? When I try to get the cookie, on an other page, it just doesnt giva any result... It just gives a blank feedback!

And Peter, now to your expires part, I knew that it was nessesary in javascript, but I didnt think of, that you allso had to do that in ASP... Glad that you told me!

When I shall put that into my code, shall I then use two lines of code? like:

Response.Cookies("poll1ansvered") = "yes"
'and
Response.Cookies("poll1ansvered").Expires = "October 25,2000"

or shall I somehow put it all into 1 line, and if that, how? I cant test what to do my self, right now, becourse the cookies dosnt work, as you know...

I hope that you can help me out, so ´that my poll will come up and running...

Casper

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

hotcut,

Try moving the

<?php
Response
.Cookies("poll1ansvered") = "yes"
?>
to the top of the page, before .

To answer your other question, yes, you have to use separate lines of code, so it should work as you typed it.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Peter got the solution to the last problem. You have to send ALL header information before you send the content. Cookies are considered part of the content.

Peter-
I forgot all about the .Expires thing. thanks!
I haven't used (client side) cookies in a while... been using server side cookies mostly for work (for security reasons), and they don't require .Expires (far as I know anyway Smiling)

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 6 posts

Joined: Oct 2000

Well hotcat i knew about the pws but thank you for remindig me about this well i think that the part which peter says about the cookie that have to appear in the head is right i had this problems when i started i hope this will solve your prob

The gray wolf from the land of might and magic

They have: 133 posts

Joined: Sep 2000

It worked!!!

I havent tryed out the expires yet... How could I posible test that, anyway Confused

Anyhow, I am really glad that it finally worked!!!

You will in a few hours (I hope) be able to see the poll in use at: casper-bang.com I hope that it will work on the w.w.w. as well...

Thank you very much for your help all, I really do apreciate that!

Thanks from
Casper

B.t.w.
Wolf, I am glad that I was able to help you a bit as well Smiling

Max, you helped me with my guestbook qustion, you (and yoiu other offcourse Smiling) can allso, in a few days, find my final (allmost) guestbook at my homepage!

They have: 133 posts

Joined: Sep 2000

I have now put my poll out on the w.w.w.!

It doesnt work!

It gives me this error:


Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Response.Cokkies'

/cbang/poll/pollproc.asp, line 3

in the first 4 lines of my page I have this:

<?php
 
Response
.Cookies("poll1ansvered") = "yes"
<strong>Response.Cokkies("pollansvered").Expires = "December 31,2000" </strong>
?>

The bold part is the part, that the error is talking about! What is the error now?

I dont understand this at all!!

Ok, my poll is here:

http://www14.brinkster.com/cbang/poll/pollenglish.asp

Hope that you can find the error! Remember: You only have 1 try, untill the cokkie sets in... If you need further code, please tell me!

Hope that you can help me; IO am counting on you!

They have: 135 posts

Joined: Apr 2000

I believe English is not your first language -- or maybe your fingers are just too fast? -- so I suggest the first thing you should probably do is try spelling "Cookies" right!! Smiling Two o's, one k....

They have: 133 posts

Joined: Sep 2000

Smiling:)Smiling:)Smiling:)

Just to let you know, I am actually one if the best in my calls in english!!! Ï am not sure, if your grades is in the 13'thens scale... 13 is the best, 8 is in the middle, I am used to get 10 (on bad days 9) soo it aint my english that is wrong!

Anyway,, it was just a bad miss spelling, that corsed thís error!!! Anyway, I do not hope to bother you w3ith any more of my bad spellings :=) even thoygh I have allready done Smiling

Anyway, I ´thank you for bothering to ansver such a silly question as this, and I am sorry to bother you with that...

I will try to, in the furture, to errorcheck my codes better... " Bad boy... BAD BOY"

Quote: some one:

"One man can lead the horse to the water,
But now even 20 can make it drink"

They have: 429 posts

Joined: Jul 2000

That proverb is:

You can lead a horse to water, but can't make it drink.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Mike,

I think hotcut was providing us with the Danish version. Wink

Regards,
Peter J. Boettcher

They have: 429 posts

Joined: Jul 2000

Sorry, us hicks don't like 'dem 'thar new fangled versions.

...Also, remind me to shoot myself for typing the above line.

They have: 133 posts

Joined: Sep 2000

Actually, the real proverb for it is, and I quote:


"One man may lead a horse to the water, but twenty cannot make him drink"

That is the real proverb; Get it from a book at my side! You are right, that the other one that I wrote was wrong, but it isnt the danish one... There is a danish proverb for that, but I cant remember how it sounds Smiling I like the english version better anyway Wink

Thats it for now...

BTW: My poll, and guestbook should be up and runnning, at the time you read this, just a few final ajustsments is needed, so that the english version will have the right layout!

Kind regards
Casper

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

sorry I've been gone for so long, been very busy. Glad your done...

Congrats!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.