Forum Moderators: open

Message Too Old, No Replies

Check for Cookie then Redirect

         

seaboy

3:24 pm on Jun 21, 2006 (gmt 0)

10+ Year Member



Please can someone help. I've spent hours looking over various javascript tutorials, and I'm going mad.
This should be *so* easy, but I need to set a 30 day cookie named "reports" on one page (and I think I've managed to do that), then check for that same cookie on another page.
If the cookie exists, then it should redirect to reports.html

That's all I need, but for some reason I can't figure it out, and keep getting errors. I'm pulling my hair out here, can anyone give me the code I need? I'll be eternally grateful!

DrDoc

3:55 pm on Jun 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps if you could post the code you have so far, and we can help you get it sorted out.

seaboy

4:11 pm on Jun 21, 2006 (gmt 0)

10+ Year Member



ok, sorry - I'm just making a mess of this. The code I have to set the cookie is:
<script language=javascript>

// Enter number of days the cookie should persist
var expDays = 300;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
expirationDate = exp.toGMTString();
// Set cookie with name and value provided
// in function call and date from above
document.cookie = "market_reports;"
document.cookie += '; expires=' + exp.toGMTString();
</script>

and then to check for that I was trying:


<script language="JavaScript" type="text/javascript">
<!--

function Get_Cookie(market_reports) {

var start = document.cookie.indexOf( market_reports+ "=" );
var len = start + name.length + 1;
if ( (!start ) &&
( name!= document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

if (market_reports == 'TRUE') {
window.location=("http://yahoo.com");
}

//-->
</script>