Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • From: javascript@xxxxxxxxxx (Podlesny, Michael)
  • Subject: [Javascript] ughh HELP WITH COOKIES PLEASE!!!!
  • Date: Mon, 25 Nov 2002 13:03:12 -0500

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C294AC.EB93E860
Content-Type: text/plain;
	charset="iso-8859-1"

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@xxxxxxxxxxx]
Sent: Monday, November 25, 2002 12:59 PM
To: javascript@xxxxxxxxxx
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@xxxxxxxxxxxx>  
To: 'javascript@xxxxxxxxxx' <mailto:'javascript@xxxxxxxxxx'>  
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));
}

 


------_=_NextPart_001_01C294AC.EB93E860
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.2722.900" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff size=2>Here 
is how I am setting it, this code is within a Perl script.&nbsp; I set the 
cookie to the username the person just logged in with and then I get the cookie 
in my header code.&nbsp; As you can see I set up an alert to see the value of 
the cookie before I do anything with it.&nbsp; This is for testing purposes 
only.</FONT></SPAN></DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff size=2>Hope 
this helps.</FONT></SPAN></DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff size=2>print 
"&lt;SCRIPT LANGUAGE=\"JavaScript\"&gt;\n";<BR>print "&lt;!-- \n";<BR>print 
"set_cookie('username','$fields{'txtusername'}');\n";<BR>print "// --&gt; 
\n";<BR>print "&lt;/SCRIPT&gt;\n";</FONT></SPAN></DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff size=2>And 
here is how I am getting it:</FONT></SPAN></DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=577100018-25112002><FONT face=Arial color=#0000ff size=2>print 
"&lt;SCRIPT LANGUAGE=\"JavaScript\"&gt;\n";<BR>print "&lt;!-- \n";<BR>print " 
alert(get_cookie('username'));\n";<BR>print "&nbsp;if (get_cookie('username') != 
null) {\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;table&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.write 
('&lt;tr&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.write ('&lt;td 
colspan=2 align=center&gt;&lt;span 
class=inputheader&gt;'+get_cookie('username')+'&lt;/span&gt;&lt;/td&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;/tr&gt;');\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
document.write ('&lt;/table&gt;');\n";<BR>print "&nbsp;}\n";<BR>print " 
&nbsp;else {\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;form method=\"post\" name=\"frmlogin\" 
action=\"\.\.\/cgi-bin\/football_survivor_log_in.pl\"&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;table&gt;');\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
document.write ('&lt;tr&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write ('&lt;td 
colspan=2 align=center&gt;&lt;span class=inputheader&gt;Log 
In&lt;/span&gt;&lt;/td&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;/tr&gt;');\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
document.write ('&lt;tr&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;td&gt;&lt;span 
class=inputheader&gt;username&lt;/span&gt;&lt;/td&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;td&gt;&lt;input type=text name=txtusername 
maxlength=25&gt;&lt;/td&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;/tr&gt;');\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
document.write ('&lt;tr&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;td&gt;&lt;span 
class=inputheader&gt;password&lt;/span&gt;&lt;/td&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;td&gt;&lt;input type=password name=pwdpassword 
maxlength=25&gt;&lt;/td&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.write 
('&lt;/tr&gt;');\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
document.write ('&lt;tr&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write ('&lt;td 
colspan=2 align=center&gt;&lt;input type=submit value=\"log 
in\"&gt;&lt;/td&gt;');\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
document.write ('&lt;/tr&gt;');\n";<BR>print 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.write 
('&lt;/table&gt;');\n";<BR>print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
document.write ('&lt;/form&gt;');\n";<BR>print "&nbsp;}\n";<BR>print "// --&gt; 
\n";<BR>print "&lt;/SCRIPT&gt;\n";</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> Terry 
  [mailto:bader@xxxxxxxxxxx]<BR><B>Sent:</B> Monday, November 25, 2002 12:59 
  PM<BR><B>To:</B> javascript@xxxxxxxxxx<BR><B>Subject:</B> Re: [Javascript] 
  ughh HELP WITH COOKIES PLEASE!!!!<BR><BR></FONT></DIV>
  <DIV><FONT face=Arial size=2>Please show us how you are calling the 
  function...</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>~ Terry<BR>757 581-5981<BR>AIM/Yahoo: 
  lv2bounce</FONT></DIV>
  <BLOCKQUOTE dir=ltr 
  style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
    <DIV 
    style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
    <A title=MPodlesny@xxxxxxxxxxxx 
    href="mailto:MPodlesny@xxxxxxxxxxxx";>Podlesny, Michael</A> </DIV>
    <DIV style="FONT: 10pt arial"><B>To:</B> <A title=javascript@xxxxxxxxxx 
    href="mailto:'javascript@xxxxxxxxxx'">'javascript@xxxxxxxxxx'</A> </DIV>
    <DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, November 25, 2002 12:52 
    PM</DIV>
    <DIV style="FONT: 10pt arial"><B>Subject:</B> [Javascript] ughh HELP WITH 
    COOKIES PLEASE!!!!</DIV>
    <DIV><BR></DIV>
    <DIV><SPAN class=522445017-25112002><FONT face=Arial size=2>ughh HELP WITH 
    COOKIES PLEASE!!!!</FONT></SPAN></DIV>
    <DIV><SPAN class=522445017-25112002><FONT face=Arial size=2>The code below 
    only saves my cookie for the page in which it is set.&nbsp; Does anyone have 
    any ideas as to why my cookie is deleted when I access the another page on 
    my sitter?</FONT></SPAN></DIV>
    <DIV><SPAN class=522445017-25112002><FONT face=Arial color=#0000ff 
    size=2></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=522445017-25112002><FONT face=Arial color=#0000ff 
    size=2>here is the code</DIV>
    <DIV><BR></DIV></FONT></SPAN>
    <DIV><FONT face=Arial color=#0000ff size=2>function set_cookie(name, value, 
    expires, path, domain, secure) {<BR>&nbsp; var curCookie = name + "=" + 
    escape(value) +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((expires) ? "; expires=" 
    + expires.toGMTString() : "") +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((path) ? 
    "; path=" +<SPAN class=522445017-25112002>&nbsp;path&nbsp;</SPAN>: "") 
    +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((domain) ? "; domain=" + domain : "") 
    +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((secure) ? "; secure" : "");<BR>&nbsp; 
    document.cookie = curCookie;<BR>}</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2>// name - name of the 
    desired cookie<BR>// * return string containing value of specified cookie or 
    null if cookie does not exist<BR>function get_cookie(name) {<BR>&nbsp; var 
    dc = document.cookie;<BR>&nbsp; var prefix = name + "=";<BR>&nbsp; var begin 
    = dc.indexOf("; " + prefix);<BR>&nbsp; if (begin == -1) 
    {<BR>&nbsp;&nbsp;&nbsp; begin = dc.indexOf(prefix);<BR>&nbsp;&nbsp;&nbsp; if 
    (begin != 0) return null;<BR>&nbsp; } else<BR>&nbsp;&nbsp;&nbsp; begin += 
    2;<BR>&nbsp; var end = document.cookie.indexOf(";", begin);<BR>&nbsp; if 
    (end == -1)<BR>&nbsp;&nbsp;&nbsp; end = dc.length;<BR>&nbsp; return 
    unescape(dc.substring(begin + prefix.length, end));<BR>}<BR><SPAN 
    class=522445017-25112002></SPAN></FONT></FONT></FONT></DIV>
    <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
    class=522445017-25112002></SPAN></FONT></FONT></FONT>&nbsp;</DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C294AC.EB93E860--