Click to See Complete Forum and Search --> : Does anyone have any idea how to use cookies?


jakykong
06-11-2003, 02:22 AM
I know most people do not like them, but it would make my life a whole lot esier and save space on my server! If anyone knows how to use cookies, any help would be apreciated!

jakykong
06-11-2003, 02:24 AM
i forgot to ask if anyone knoes of a matching field tpe of script to redirect a user to a pecific page after writing some info to a cookie? If anyone does, it would be nice to know.

AdamGundry
06-11-2003, 03:21 AM
You can redirect to another page using this:
window.location = 'page.html';

Write a cookie using this:
document.cookie = 'Name=Value';

And read it using a function like this:GetCookieVariable('Name'); // Returns the value of the cookie called 'Name'.

// Script by Adam Gundry, http://www.agbs.co.uk/
function GetCookieVariable(name){
s = '; ' + document.cookie;
r = new RegExp('; ' + name + '=', 'gi');
p = s.search(r);
if (p != -1){
s = s.substring(p+name.length+3,s.length);
p2 = s.indexOf(';');
if (p2 == -1) p2 = s.length;
m = s.substring(0, p2);
return m;
}
return false;
}

Hope this helps

Adam

sceeuk
12-10-2006, 11:32 PM
Yes.

sceeuk
12-10-2006, 11:37 PM
Try this. i made this a while ago.


Javascript: How to use cookies and interact with them.

Made by myself. Others are allowed to use this freely without my consent.

http://www.freewebs.com/sceeuk/index.htm



Hope this helps.

Does anyone know how to use Cookies? http://www.freewebs.com/sceeuk/index.htm

sceeuk
12-10-2006, 11:40 PM
From my website at freewebs.com: http://www.freewebs.com/sceeuk/index.htm

Made by myself. Others are allowed to use this freely without my consent.

felgall
12-11-2006, 01:48 AM
Cookies can be read and written from Javascript and also most server side languages. There are three types of cookies -

session cookies are stored in the browser itself and are deleted when the browser is closed
first party cookies are set by the site you are visiting
third party cookies are set by the ads on the site you are visiting (these are the ones you need to turn off)

kiwibrit
12-11-2006, 03:27 AM
I think it would be better to use a server, here. Not everybody, or every device has javascript enabled. If you have access to php, here's a starting tutorial (http://www.phpfreaks.com/tutorials/120/0.php).

jakykong
12-14-2006, 07:02 PM
Ironic. This particular post has not been looked at for 3 years, and, long after the problem was solved, someone posts a reply starting the whole thing up again. :p

Not to be rude, thanks for the help -- I'll certainly know where to send anyone else who asks me :cool:

This just reminds me of a joke i heard a while ago about how to ask for something on a lightbulb. You get like 1,000 people responding, then the post dies. Then someone replies and starts the whole process again.

Cheers!