Click to See Complete Forum and Search --> : cookies


Brandon
02-18-2003, 07:25 AM
hi everyone.

Alright so I have a question. Eventually I'll probably have hundreds more. So here it is:

Say you have a cookie set on the main page of the website, the person enters their name, and, it's set. And so they go on heir merry way and it calls them by their name whatever. But say a person comes into another page, and does not, for some reason, enter through the main page. Is it possible hat I can make it so they are taken automatically do that main page so they can fill the thing out? It doesn't seem that much to ask for, seems quite simple, I just can't figure it out.

Thank you!

Brandon
P.S. the script I have for the cookie, is attached to this message. the first script is to set the cookie and thsecond to retrieve it.

khalidali63
02-18-2003, 08:46 AM
Just add one condition in the readCoockie method or the method/function that reads the cookie that if(cookieValue!=""){
//then you know that cookie is created.
//so let them view the pages
else{
//no valu in cookie so redirect them
//to the first page
document.location.href="firstPage.html"
}

hope this helps

Cheers

Khalid

Brandon
02-18-2003, 03:07 PM
hi,

ok, can you give me copy of the script I attached, with your suggestion added in there? I'm not sure where to add it. thank you

Brandon

Originally posted by khalidali63
Just add one condition in the readCoockie method or the method/function that reads the cookie that if(cookieValue!=""){
//then you know that cookie is created.
//so let them view the pages
else{
//no valu in cookie so redirect them
//to the first page
document.location.href="firstPage.html"
}

hope this helps

Cheers

Khalid

pyro
02-18-2003, 07:13 PM
The code that kahlidali63 gave you goes on the top of each of your pages. What it does is checks to see if the cookie has a value (ie. the cooke has been set), and if it does, doesn't do anything. But, if it does not (ie. the cookie has not been set), redirects you to firstPage.html

Brandon
02-18-2003, 07:36 PM
hi,

ok, but in the code, it did not give an action for the if statement. why is this? can you give the code again? does it go within th cookie script?

Originally posted by pyro
The code that kahlidali63 gave you goes on the top of each of your pages. What it does is checks to see if the cookie has a value (ie. the cooke has been set), and if it does, doesn't do anything. But, if it does not (ie. the cookie has not been set), redirects you to firstPage.html

pyro
02-18-2003, 07:42 PM
You didn't give an action to the if statement because this line

if (cookieValue != "")

Checks to see if the cookie contains a value, and if it does, we don't want it to do anything. That is why the else statement contains code. You could actually do it like this instead.

if (cookieValue == "")
{
document.location.href = "firstPage.html";
}

This code is inserted in the <head> of each of your pages, not the cookie code.

Brandon
02-18-2003, 07:56 PM
hi,

ok, so what I did was put the sript language="javacript" around it, well ending with /script. but now by cookieValue do you mean the name of the cookie or just write cookieValue. And you say this goes outside of the script? just this code? I'm trying to get this to work now...no luck yet.


Originally posted by pyro
You didn't give an action to the if statement because this line

if (cookieValue != "")

Checks to see if the cookie contains a value, and if it does, we don't want it to do anything. That is why the else statement contains code. You could actually do it like this instead.

if (cookieValue == "")
{
document.location.href = "firstPage.html";
}

This code is inserted in the <head> of each of your pages, not the cookie code.

pyro
02-18-2003, 08:07 PM
This is how I'd actually do this...

<script language="javascript" type="text/javascript">
if (document.cookie == "")
{
document.location.href = "firstPage.html";
}

Brandon
02-18-2003, 08:30 PM
hi,

Hallelujah it works!
Thank you very much. I tested this thing and it is beautiful.
thank you

Brandon
Originally posted by pyro
This is how I'd actually do this...

<script language="javascript" type="text/javascript">
if (document.cookie == "")
{
document.location.href = "firstPage.html";
}

Brandon
02-18-2003, 08:45 PM
hi another time
one more question.

it doesn't matter if you have other scripts in the head commands also does it? I have a few other scripts in there, just hoping they don't interfere with each other or something.

Brandon

Originally posted by Brandon
hi,

Hallelujah it works!
Thank you very much. I tested this thing and it is beautiful.
thank you

Brandon

pyro
02-18-2003, 08:48 PM
No, they shouldn't interfere. The only thing that would is if you have another redirect. If you do, just make sure that this one is first...