Forum Moderators: open

Message Too Old, No Replies

How to save user name in a cookie?

         

dreaming of nascar

11:13 pm on Feb 10, 2003 (gmt 0)

10+ Year Member


I am trying to figure out how to set a cookie like this...

When a person comes to my site, they have the option of entering their name and other info. into a form. When they click submit I want to be able to save their name to a cookie. How do I get the information from the form and set it in a cookie?

dreaming of nascar

ppg

11:25 pm on Feb 10, 2003 (gmt 0)

10+ Year Member



I believe that will depend on what scripting language you are using - php? asp?

dreaming of nascar

11:31 pm on Feb 10, 2003 (gmt 0)

10+ Year Member



I would like to set the cookie and gather the info using JavaScript if possible. Is it?

Chuma

11:31 pm on Feb 10, 2003 (gmt 0)

10+ Year Member



Using ASP:

Response.Cookies("item_name") = Request("value from form")
Response.Cookies("item_name").domain = "your domain name"
Response.Cookies("item_name").path = "directory it applies to"
Response.Cookies("item_name").expires = #date#

(You need to update all the values if you want to update the cookie later.)

Thanks.

ppg

11:50 pm on Feb 10, 2003 (gmt 0)

10+ Year Member



yes it is, have a look at the javascript document.cookie property, a basic one would be something like:

document.cookie = "name=value";

You might want to look at setting the expiry time, the path etc too, which you could do with a function.

Sorry I can't be more specific but I don't use javascript

midi25

4:48 pm on Feb 12, 2003 (gmt 0)

10+ Year Member



ASP is ideal for reading in form values and then reading and writing cookies.

a simple

<%
Response.Cookies(Mywebsite)(name) = Request.Form("name")
Response.Cookies(Mywebsite)(email) = Request.Form("email")
Response.Cookies(Mywebsite(age) = Request.Form("age")
Response.Cookies(Mywebsite).Expires Now()+365
%>

This will create a cookie on the clients pc and store the values of their name, email, and age.

Maybe you dont want to go down the ASP road but when you are making your pages interactive then you should prob consider a langauge like ASP,PHP,JSP for the future.