Gossamer Forum
Home : Products : DBMan : Customization :

Cookie help

Quote Reply
Cookie help
I need some help with a cookie mod I have installed. Its obviously not done right, but with all the different types and things, im confused. Plus with the fact that I have this installed as a javascript on a static html page and not inside the script itself, I cant figure this out.

This is what I have at the top of my page in my head tags:

Code:
<SCRIPT LANGUAGE=JAVASCRIPT>
// Extract the value from the cookie at the given offset.

function GetValue( Offset )
{
var End = document.cookie.indexOf (";", Offset);
if( End == -1 )
End = document.cookie.length;

// Return the portion of the cookie beginning with the offset
// and ending with the ";".

return unescape( document.cookie.substring( Offset, End) );
}

function GetCookie( Name )
{
var Len = Name.length;

// Look at each substring that's the same length as the cookie name
// for a match. If found, look up the value and return it.

var i = 0;
while( i < document.cookie.length )
{
var j = i + Len + 1;
if( document.cookie.substring( i, j) == (Name + "=") )
return GetValue( j );
i = document.cookie.indexOf( " ", i ) + 1;
if( i == 0)
break;
}
var a = "";
return a;
}

// Create or change a cookie given its name and value. The name and value
// are required, but the expiration date isn't. Note that if you don't specify
// an expiration date, the cookie only exists for the current session.

function SetCookie( Name, Value, Expire )
{
document.cookie = Name + "=" + escape( Value ) + ";expires=" + Expire;
}

// Write all the cookies for the form1 form.

function WriteCookies()
{
// var Expire = "Friday,25-Feb-2000 12:00:00 GMT";
var Expire = "$cookie_expiration_date";

with( document.form1 )
{
SetCookie( "username", userid.value, Expire );
SetCookie( "password", pw.value, Expire );
}
}

// Load the form with the values in the cookie

function GetCookies()
{
with( document.form1 )
{
userid.value = GetCookie( "username" );
pw.value = GetCookie( "password" );
auth_remember_login.value = GetCookie( "remember_login" );

if ( auth_remember_login.value == "on" ) {
auth_remember_login.checked = true; }

}
}

function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) // Except on the Mac - ahead of its time
date.setTime (date.getTime() - skew);
}

var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); // 365 days from now

function IsValid()
{
blnValid = true;

with( document.form1 )
{
if(( userid.value == "" ) || ( pw.value == "" ))
{
window.alert( "You must enter both your user name and your password" );
blnValid = false;
}

var Username = userid.value;
var Password = pw.value;

if (auth_remember_login.checked) {
var Remember_login = "on";
}

}
if( blnValid )

if (Remember_login == "on") {
document.cookie = "username=" + Username + ";expires=" + expdate.toGMTString() + ";";
document.cookie = "password=" + Password + ";expires=" + expdate.toGMTString() + ";";
document.cookie = "remember_login=" + Remember_login + ";expires=" + expdate.toGMTString() + ";";
}

if (Remember_login != "on") {
var Expires = "-1";
document.cookie = "username=" + Username + ";expires=" + Expires + ";";
document.cookie = "password=" + Password + ";expires=" + Expires + ";";
document.cookie = "remember_login=" + Remember_login + ";expires=" + Expires + ";";
}

return blnValid;
}

</SCRIPT>

and my form is this:

Code:
<form action="http://www.wdu.net/cgi-local/dbman/db.cgi" method="post" name="form1" OnSubmit="return IsValid()">
<input type=hidden name="db" value="default">
<input type=hidden name="uid" value="">
<font size=-2>Username</font><br>
<input type="TEXT" name="userid" size="10"><br>
<font size=-2>Password</font><br>
<input type="PASSWORD" name="pw" size="10"><br>
<font size=-2>Remember password?</font>&nbsp;<INPUT type="checkbox" name="auth_remember_login"><br>
<input type="SUBMIT" name="login" value="Go!">

what Im looking for it to do, or hoping it can do is when someone logs in successfully, then goes back to the main page again within the time that the cookie is intact and hasnt timed out, I want it to show their username in the username field so they dont have to type it in, they would just have to type in their password for security. Either that, or their username and password would be entered into the fields (the password would be coded with *** or something) and they would just have to click on go. I guess the latter would make more sense since I have the remember password box included.
Can anyone help me with this? I dont know if it isnt working because its using script tags and its outside of the script or what, but Im not sure how to fix it. Thanks! Smile

Steffani
Quote Reply
Re: [wdu2002] Cookie help In reply to
I haven't used the cookie mod so can't be of much help. There are various threads that do deal with using cookies.

I did however notice that you have:

var Expire = "Friday,25-Feb-2000 12:00:00 GMT";

You should change that date to one which is in the future and not 2000.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [wdu2002] Cookie help In reply to
Bumping this up to see if anyone else can help



BTW, thanks Lois! Smile