...

View Full Version : Using cookies



JAVAEOC
02-08-2004, 04:28 PM
How can i use use my cookies to retrive data?

Edit: a use too much --> delete

Antoniohawk
02-08-2004, 08:11 PM
Check out this tutorial on cookies.

http://hotwired.lycos.com/webmonkey/98/29/index1a_page7.html?tw=programming

JAVAEOC
02-08-2004, 08:56 PM
<script>
var the_name = prompt("What's your name?","");
document.cookie = the_name;
alert("Thanks, now go to the next page.");
</script>

TO SET THE COOKY

<script>
var the_cookie = document.cookie;
alert("Your name is: " + the_cookie);
</script>

TO READ IT

but how did it know which cooky to read

Willy Duitt
02-08-2004, 09:07 PM
Originally posted by JAVAEOC
but how did it know which cooky to read

Evidently, you looked at the first script example without reading the tutorial.

Perhaps you should try first reading the tutorial, then asking
for clarification on a particular point you do not understand.

.....Willy

JAVAEOC
02-08-2004, 09:11 PM
I did read the tuturial thats how i knew i can delelte all the extra stuff :(

but on page 10 i get terrible lost

JAVAEOC
02-08-2004, 10:00 PM
Now I tried this

var broken_cookie = document.cookie.split(":");
var RightClick = broken_cookie[0];
var StyleNum = broken_cookie[1];
if(document.cookie==''){RightClick=0;StyleNum=0}

if(document.cookie==''){RightClick=0;StyleNum=0} this was for when the user logs on the page for the first time, so it still displays a style sheet.

This worked great on my PC :thumbsup:
just as i wanted it to

but now i uploaded it to my server (brinkster.com) and it chages the cookie in some way it adds a weird Brinkster=0 or Brinkster=3 or sometimes just this #LSDAKJFSLKAF#DLKSJF0923490USD78923#@$LKSFJD

just random numbers and letters

this makes it impoosbile for me to retrive the information i stored.....

please help.

Here the link to the broken page -->

http://www34.brinkster.com/dgothe/db/DominiksBeta.html

it will alert the cookie value at the beginning so that you see whats going on

thanks alot

JAVAEOC
02-08-2004, 10:04 PM
I added this:

var broken = document.cookie.split(";");
var broken_cookie = broken[1].split(":");

now it works.... thanks for all the given help

JAVAEOC
02-09-2004, 01:50 AM
On this page i am using cookies
http://www34.brinkster.com/dgothe/db/DominiksBeta.html

they work great when i hit the refresh button but they do not work if i close the browser and reopen it

why?

Basscyst
02-09-2004, 02:07 AM
You have to set the expiration date of the cookie.

http://hotwired.lycos.com/webmonkey/98/29/index1a_page12.html?tw=programming

Basscyst

JAVAEOC
02-09-2004, 02:46 AM
GOSH

I am so lost please help me write a simple cookie script

i tried the tutorial but im too dumnb for it

please....

all i need is to store and retrive two variables.... please

thanks for any help

JAVAEOC
02-09-2004, 11:20 PM
The script on this page doesnt work, why?

http://www34.brinkster.com/dgothe/cookie.htm

it works fine on my hard drive but it doesnt work when i upload it....

thnaks

glenngv
02-10-2004, 04:56 AM
One or more cookies can be saved in the browser. So cookie names do not always located at the start. In your page, the cookie string is:

BrinksterServer=1; cookey=muahah

Your script assumes the cookie is always at the start that's why your script fails when looking for cookey. There are many cookie scripts in the internet and in this forum, why not use them?

Here's one from Post a Javascript forum:
http://www.codingforums.com/showthread.php?s=&threadid=11585

JAVAEOC
02-10-2004, 11:17 PM
Glenn... thanks for that, but i already saw it...

Well the stuff they where doing there was WAY over my small head... So i wasnt able to throw together a working html file

that is why i started this thread...

so I would really appreciate it if you could throw together a working script and attach it....

thanks alot

glenngv
02-11-2004, 02:52 AM
The code in the link I gave you is already a working script and easy to use. It has attachment of the full documentation on its usage. Did you even try to create a simple page using that script?

JAVAEOC
02-11-2004, 03:27 AM
glenngv... heres what i am having truble with:

OK the script works fine, the thing now is that when i alert(document.cookie) then it is supposed to alert all the cookies ... right?

but it doesnt it doesnt alert the cookie that i jsut set... why?

P.S. the reason why I didnt get the script to work is because i misspelled the cookie name:o lol and my javascirpt console is broke so....

thanks glenngv :D

JAVAEOC
02-11-2004, 03:47 AM
Looking back:

it doesnt work... lol i uploaded it and now it doesnt work :(

http://www34.brinkster.com/dgothe/New%20Text%20Document.htm

it neve creates a new cookie at all.

glenngv
02-11-2004, 04:23 AM
You have to call the set method.

function AddMyCookie(AName, AValue, EXNUM){
cookies.add(AName, AValue); // Add cookie to collection
cookies[AName].expiresIn(EXNUM); // Set expiration
cookies[AName].set(); //save cookie
}

function ReadMyCookie(){
var cookieValue;
if(cookies.get('Muahah')){cookieValue=cookies['Muahah'].value;}
alert(cookieValue)
}

JAVAEOC
02-11-2004, 07:24 PM
yes.. thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum