Closed Thread Icon

Topic awaiting preservation: Set Cookie/Another page redirects (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=8603" title="Pages that link to Topic awaiting preservation: Set Cookie/Another page redirects (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Set Cookie/Another page redirects <span class="small">(Page 1 of 1)</span>\

 
intcon
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 04-15-2003 00:52

Hello!
I am a non-javascript writing person (egads) so, please bear with me on this one!
I have a form on a page, I want people to fill out. (I'm good so far) From this form, I'll take their email address, and send them an autoresponder. (Still good to go) On the autoresponder page, I want to place a link to another page. (here comes the hard part) That page will give them a cookie. Just a plain cookie. No fancy stuff. Just a little bit of code so the next part works.
THEN, I need another piece of code, so that when said person with the cookie goes back to the form page, it automatically sees the cookie and redirects them to yet another page.(as they've already filled out the form, and their email address has been proven to work, I want them to see a different page instead of the form again)
I've spent probably 30 hours researching this, and have totally given up being able to do it myself. pllllllllllllllleeeeeeeeeeeeeease help! (notice the blubbering and pathetic pleas)

carrie

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-15-2003 01:11

First of all, look into a server-side solution, as this will not work for users who have JavaScript disabled:

// to set the cookie:
var expires = new Date();
// set expiration date to right now plus 1000 milliseconds/second * 60 seconds/minute * 60 minutes/hour * 24 hours/day * 30 days
expires.setDate(expires.getDate()+1000*60*60*24*30);
// set the cookie: name=value; expires=expiration_date; path=minimum_path_cookie_can_be_retrieved_from
document.cookie = "emailvalidated=true; expires="+expires.toGMTString()+"; path=/";

Put all that in a function called from the page that successfully validated the email. To check if the cookie is there later on, use this code:

// to read the cookie:
// (note that document.cookie does not take the exact value we set it to; document.cookie behaves strangely like this)
var cookies = document.cookie.split(';');
var emailvalid = false;
for (var a=0; a < cookies.length; a++)
{
// check each cookie to see if it's the one we want
if (cookies[a].indexOf("emailvalidated=true") != -1)
{
emailvalid= true;
}
}
// check if we found the cookie
if (emailvalid)
{
location.replace("INSERT_URL_HERE"); // forwards to the new location without leaving this page as an entry in the back-button history
}

Give that a shot. It's possible I mistyped or misremembered something.

Maskkkk
Paranoid (IV) Inmate

From: Willaimsport, PA, US of A the hole in the Ozone
Insane since: Mar 2002

posted posted 04-15-2003 01:13

May I redirect you (no pun intended) to the FAQ - C is for Cookie its good enough for me in Javascript?

And redirect you to the redirect you to the other part of the FAQ - On redirection using JavaScript

Crap Slime beat me too it oh well he's smarter than me....take his advise.



- Face the Present
- AIM: MASKKKK

[This message has been edited by Maskkkk (edited 04-15-2003).]

intcon
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 04-15-2003 01:46

omg, you guys are quick!
so, I tried it in Netscape, worked like a charm.....then I tried it in IE, and it wouldn't redirect? or maybe that "validate email" thing is throwing it off?
I don't really need to validate the email, as the only way they can get to the page is if they get their autoresponded email and click on the link in it (which gives them the cookie, which takes them to the redirected page, yadda yadda yadda)....make sense? or am I blathering again?
is there a pain in the a** award on this site? I'm sure I qualify.....=)

carrie
btw I love how these forms are with the black background and red text...very chic

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-15-2003 03:38

"emailvalidated" is simply the name of the cookie that's set to remember whether they've already gone through the email process or not.

If you can't figure out what's wrong with it in IE by yourself, you'll probably have to provide a link to the page so that we can test it out. Unless someone can find an error in my code. Otherwise, it'll be hard to find what's going wrong without a working example.

intcon
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 04-15-2003 05:03

ohhhhh.........trust me, there's no way I can figure this one out by myself! LOL.....I've been working on it for two weeks, I've pulled almost all my hair out, and the remaining hair is turning gray!
Here's what I am working with...
This is the page that would have the form on it....(and also the page where the redirect is) http://www.datahunter.com/test3/priceform.html
This is the page where the cookie is http://www.datahunter.com/test3/set_the_cookie.html
And this is the page that the page should redirect to if you have the cookie http://www.datahunter.com/test3/pricelist.html
So, if I go to priceform.html, it shows me the form, then I go to set_the_cookie.html (love the name eh?)and it sets the cookie, so if I go back to priceform.html it should see the cookie and redirect me to pricelist.html. right? (am I going about this the hard way?)
Whew
Now, I'm pretty sure I've done something reeeeeeeeeeeealllllly amazingly stupid in the coding, something that tomorrow you can say, "You should have seen what this lady did last night!" - but I admit to not knowing javascript; but at least I'm always good for gossip around the water cooler!
Did I mention your help is greatly appreciated? It truly is....
=)

carrie


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-15-2003 05:11

Whoops, I screwed up, it should be setTime and getTime instead of setDate and getDate on the set_the_cookie page.

intcon
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 04-15-2003 07:44

slime...i love you!!!!!!!!!!!!!!!!!!!!!!!!!! weeks and weeks and hours and hours of work are finally at an end!!! bless you, my child.
maybe now my hair will grow back - my fingers will untangle from their claws bent over the keyboard - and I wll never have to type "javascript cookie for idiots" into the google search engine again!
smiles from ear to ear (and a small glisten in my eye)
major hugs!

carrie

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-15-2003 17:14

Heh, you're welcome. =) Now go over the code until you understand how it works, k?

intcon
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 04-16-2003 06:35

Hi Slime...
It's me again!!! I have just one more question......(well, no promises on that one)
so, using the previous code on the previous pages, I just discovered that I need to put a cookie on the pricelist.html page, so that if someone DOESN'T have a cookie, it redirects them to the priceform.html page....(oh, this makes my head spin)
so, what I did was take the code with the redirect on it...
<script language="JavaScript" type="text/JavaScript">
// to read the cookie:
// (note that document.cookie does not take the exact value we set it to; document.cookie behaves strangely like this)
var cookies = document.cookie.split(';');
var emailvalid = false;
for (var a=0; a < cookies.length; a++)
{
// check each cookie to see if it's the one we want
if (cookies[a].indexOf("emailvalidated=true") != -1)
{
emailvalid= true;
}
}
// check if we found the cookie
if (emailvalid)
{
location.replace("http://www.datahunter.com/test3/pricelist.html"); // forwards to the new location without leaving this page as an entry in the back-button history
}
and I reversed it.....heh...without knowing what I was doing whatsoever.....lol.....nothing new for me I'll tell you...
so here's what I had...
<script language="JavaScript" type="text/JavaScript">
// to read the cookie:
// (note that document.cookie does not take the exact value we set it to; document.cookie behaves strangely like this)
var cookies = document.cookie.split(';');
var emailvalid = true;
for (var a=0; a < cookies.length; a++)
{
// check each cookie to see if it's the one we want
if (cookies[a].indexOf("emailvalidated=false") != -1)
{
emailvalid= false;
}
}
// check if we found the cookie
if (emailvalid)
{
location.replace("http://www.datahunter.com/test3/priceform.html"); // forwards to the new location without leaving this page as an entry in the back-button history
}
</script>
I (quite cleverly) changed all the falses to trues, and all the trues to falses...(are you falling over in hysterics yet?)....my reasoning being that if in the first bit of code it FOUND the cookie, it redirected you to pricelist.html, but if it DIDN'T find the cookie, it redirects you priceform.html.....
Here's the page with my original (don't laugh) bit of javascript.... www.datahunter.com/test3/pricelist_false.html
so, if I go to that page without a cookie, it sends me to the priceform.html page - perfecto!
then, I go to set_the_cookie.html (to ...well....set the cookie), and then when I go back to the pricelist_false.html, it redirects me to pricelist.html (when it should really be showing pricelist_false.html)
how did I do that? what happened? am I double redirecting?
you're right, I really do need to study it, to figure out what on earth is going on.....but I think I've double-crossed-redirected myself here...
any brilliant thoughts?

carrie

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-16-2003 07:47

It has to do with how you changed the code.

Simple solution: change "emailvalidated=false" back to "emailvalidated=true". The former will *never* be a cookie that's been set, so it will *always* send you to priceform.html - at which point, if you *do* have the cookie set, it will redirect you to pricelist.html.

Better solution: rather than changing all trues to falses and falses to trues, you could simply replace this line:

if (emailvalid)

(which asks "was the cookie set?")
with this line:

if (emailvalid == false)

(which asks, "was the cookie not set?")

intcon
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 04-16-2003 16:56

Thank you once again Slime! It works like a charm.....now I just have to figure out what all of it means....lol...
Much appreciated!!!

carrie

« BackwardsOnwards »

Show Forum Drop Down Menu