[Javascript] ughh HELP WITH COOKIES PLEASE!!!!

Podlesny, Michael MPodlesny at acsisinc.com
Mon Nov 25 12:03:12 CST 2002


Here is how I am setting it, this code is within a Perl script.  I set the
cookie to the username the person just logged in with and then I get the
cookie in my header code.  As you can see I set up an alert to see the value
of the cookie before I do anything with it.  This is for testing purposes
only.
 
Hope this helps.
 
print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
print "<!-- \n";
print "set_cookie('username','$fields{'txtusername'}');\n";
print "// --> \n";
print "</SCRIPT>\n";
 
And here is how I am getting it:
 
print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
print "<!-- \n";
print " alert(get_cookie('username'));\n";
print " if (get_cookie('username') != null) {\n";
print "       document.write ('<table>');\n";
print "         document.write ('<tr>');\n";
print "        document.write ('<td colspan=2 align=center><span
class=inputheader>'+get_cookie('username')+'</span></td>');\n";
print "        document.write ('</tr>');\n";
print "       document.write ('</table>');\n";
print " }\n";
print "  else {\n";
print "       document.write ('<form method=\"post\" name=\"frmlogin\"
action=\"\.\.\/cgi-bin\/football_survivor_log_in.pl\">');\n";
print "       document.write ('<table>');\n";
print "        document.write ('<tr>');\n";
print "         document.write ('<td colspan=2 align=center><span
class=inputheader>Log In</span></td>');\n";
print "        document.write ('</tr>');\n";
print "        document.write ('<tr>');\n";
print "         document.write ('<td><span
class=inputheader>username</span></td>');\n";
print "         document.write ('<td><input type=text name=txtusername
maxlength=25></td>');\n";
print "        document.write ('</tr>');\n";
print "        document.write ('<tr>');\n";
print "         document.write ('<td><span
class=inputheader>password</span></td>');\n";
print "         document.write ('<td><input type=password name=pwdpassword
maxlength=25></td>');\n";
print "        document.write ('</tr>');\n";
print "        document.write ('<tr>');\n";
print "         document.write ('<td colspan=2 align=center><input
type=submit value=\"log in\"></td>');\n";
print "        document.write ('</tr>');\n";
print "       document.write ('</table>');\n";
print "       document.write ('</form>');\n";
print " }\n";
print "// --> \n";
print "</SCRIPT>\n";

-----Original Message-----
From: Terry [mailto:bader at tcbader.com]
Sent: Monday, November 25, 2002 12:59 PM
To: javascript at LaTech.edu
Subject: Re: [Javascript] ughh HELP WITH COOKIES PLEASE!!!!


Please show us how you are calling the function...
 
~ Terry
757 581-5981
AIM/Yahoo: lv2bounce

----- Original Message ----- 
From: Podlesny, Michael <mailto:MPodlesny at acsisinc.com>  
To: 'javascript at LaTech.edu' <mailto:'javascript at LaTech.edu'>  
Sent: Monday, November 25, 2002 12:52 PM
Subject: [Javascript] ughh HELP WITH COOKIES PLEASE!!!!

ughh HELP WITH COOKIES PLEASE!!!!
The code below only saves my cookie for the page in which it is set.  Does
anyone have any ideas as to why my cookie is deleted when I access the
another page on my sitter?
 
here is the code

function set_cookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
 
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie
does not exist
function get_cookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20021125/e0c5a398/attachment.htm>


More information about the Javascript mailing list