[thelist] Weird cookie/ASP problem

Sean Rhea Sean.Rhea at state.tn.us
Mon Apr 22 15:32:01 CDT 2002


This is a MIME message. If you are reading this text, you may want to 
consider changing to a mail reader or gateway that understands how to 
properly handle MIME multipart messages.
--
[ Picked text/plain from multipart/alternative ]
Hi guys,

I have attached a code sample to demonstrate my problem. Basically, before I
get into the ASP, I set my "user" session variable. Change 1-4 fields (which
sets 1-4 cookies) and that user session variable stays active. The moment I set
a 5th cookie, the user session variable gets dropped. I have asked on the ASP
discussion groups and no one seems to have a clue. I think the javascript
cookie functions are causing my session to be broken upon writing my 5th
cookie, but I have no idea why.

Any insight anyone can give as to what's going on here would be GREATLY
appreciated!

Thanks,
Sean Rhea

----------

<%
if not session("user") <> "" then
Response.Redirect("login.asp")
end if
Response.CacheControl = "no-cache"
Response.Expires = -1
SET CN = server.CreateObject("ADODB.Connection")
CN.Provider = "SQLOLEDB"
CN.ConnectionString = "DATA SOURCE=127.0.0.1; INITIAL CATALOG=prospect; USER
ID=sysadmin; PASSWORD=blahblah"
CN.Open
%>

<html>
<head>
<title>Prospect Package - Main</title>
<script>

function addtoPkg(sel_num,state,type) {
document.form1.sel_num.value = sel_num;
document.form1.state.value = state;
document.form1.process.value = "normal";
if (type == "B") {
document.form1.source.value = "99B";
} else {
document.form1.source.value = "99S";
}
document.form1.submit();
}

function editButton() {
document.form1.process.value = "edit";
document.form1.submit();
}

function finishButton() {
if (isBlank(document.form1.pname.value)) {
alert("You MUST provide a name!");
document.form1.pname.focus();
} else {
document.form1.submit();
}
}

function submitChange() {
document.form1.process.value = "change";
document.form1.submit();
}

function deletePkg() {
if (confirm("Are you sure you want to delete this package?"))
{
document.form1.process.value = "delete";
document.form1.submit();
}
}

function abortPkg1() {
window.location.href = "main.asp";
}

function abortPkg2() {
document.form1.process.value = "abort";
document.form1.submit();
}

function isBlank(testStr)
{
if (testStr.length == 0) // nothing entered?
return true
for (var i = 0; i <= testStr.length-1; i++) // all spaces?
if (testStr.charAt(i) != " ")
return false
return true
}

function setCookie(n, v) {
var cookieStr = "";
cookieStr = n + " = " + v;
document.cookie = cookieStr;
}


function getCookie (name) {
var dcookie = document.cookie;
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dcookie.substring(cbegin, vbegin) == cname) {
var vend = dcookie.indexOf (";", vbegin);
if (vend == -1) vend = clen;
return unescape(dcookie.substring(vbegin, vend));
}
cbegin = dcookie.indexOf(" ", cbegin) + 1;
if (cbegin == 0) break;
}
return "";
}

function getMyCookie() {
document.form1.pname.value = getCookie("pname");
document.form1.company.value = getCookie("company");
document.form1.addr1.value = getCookie("addr1");
document.form1.addr2.value = getCookie("addr2");
document.form1.city.value = getCookie("city");
document.form1.state.value = getCookie("state");
document.form1.zip.value = getCookie("zip");
document.form1.attachment1.value = getCookie("attachment1");
document.form1.attachment2.value = getCookie("attachment2");
document.form1.attachment3.value = getCookie("attachment3");
document.form1.attachment4.value = getCookie("attachment4");
document.form1.attachment5.value = getCookie("attachment5");
document.form1.attachment6.value = getCookie("attachment6");
document.form1.other.value = getCookie("other");
document.form1.email.value = getCookie("pemail");

delCookie("pname");
delCookie("company");
delCookie("addr1");
delCookie("addr2");
delCookie("city");
delCookie("state");
delCookie("zip");
delCookie("attachment1");
delCookie("attachment2");
delCookie("attachment3");
delCookie("attachment4");
delCookie("attachment5");
delCookie("attachment6");
delCookie("other");
delCookie("pemail");

}

function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

</script>

<style type="text/css">
<!--
a:hover { font-style: normal; color: #FFFFFF; background-color: #49576D}
-->
</style>
</head>

<body bgcolor="#49576D" text="#000000" link="#49576D" vlink="#7E8E77">
<%
session("PROSPECTNO") = "111111"
%>
<form action="main.asp" method="post" name="form1" id="form1">
<table width="75%" border="0" cellpadding="3" cellspacing="0"
align="center"><tr><td>
<table width="100%" border="0" cellpadding="0" cellspacing="3">
<tr><td align="right"><font color="#78879D"><b>Prospect
#:</b></font></td><td width="10%"><%response.write
session("PROSPECTNO")%></td><td>&nbsp;</td></tr>
<tr><td align="right"><font
color="#78879D"><b>Email:</b></font></td><td><input type="text" name="email"
id="email" value="<%Response.write session("EMAIL")%>"
onBlur="setCookie('pemail',this.value)"></td><td><a href="final_rpt1.asp">Print
Table of Contents</a></td></tr>
<tr><td align="right"><font
color="#78879D"><b>Name:</b></font></td><td width="10%"><input type="text"
name="pname" id="pname" value="<%Response.write session("PNAME")%>"
onBlur="setCookie('pname',this.value)"></td><td><a href="final_rpt2.asp">Print
Buildings</a></td></tr>
<tr><td align="right"><font
color="#78879D"><b>Company:</b></font></td><td><input type="text"
name="company" id="company" value="<%Response.write session("COMPANY")%>"
onBlur="setCookie('company',this.value)"></td><td><a
href="final_rpt3.asp">Print Sites</a></td></tr>
<tr><td align="right"><font
color="#78879D"><b>Address:</b></font></td><td><input type="text" name="addr1"
id="addr1" value="<%Response.write session("ADDR1")%>"
onBlur="setCookie('addr1',this.value)"></td><td><a href=""></td></tr>
<tr><td align="right"><font
color="#78879D"><b>:</b></font></td><td><input type="text" name="addr2"
id="addr2" value="<%Response.write session("ADDR2")%>"
onBlur="setCookie('addr2',this.value)"></td><td></td></tr>
<tr><td align="right"><font
color="#78879D"><b>City/State/Zip:</b></font></td><td><input type="text"
name="city" id="city" value="<%Response.write session("CITY")%>"
onBlur="setCookie('city',this.value)">&nbsp;<input type="text" name="state"
id="state" size="2" value="<%Response.write session("STATE")%>">&nbsp;<input
type="text" name="zip" id="zip" size="10" value="<%Response.write
session("ZIP")%>"></td><td align="center"></td></tr>
<tr><td align="right"><font
color="#78879D"><b>Attachments:</b></font></td><td><input type="checkbox"
id="attachment1" name="attachment1" value="Tax Brochure"<%if
session("ATTACHMENT1") = "Tax Brochure" then Response.Write " checked"%>
onChange="setCookie('attachment1',this.value)"><a
href="pdf/taxbrochure.pdf">Tax Brochure</a></td><td align="center"></td></tr>
<tr><td align="right">&nbsp;</td><td><input type="checkbox"
id="attachment2" name="attachment2" value="Automotive Brochure"<%if
session("ATTACHMENT2") = "Automotive Brochure" then Response.Write " checked"%>
onChange="setCookie('attachment2',this.value)"><a href="pdf/autobrochure.pdf"
target="_blank">Automotive Brochure</a></td><td align="center"></td></tr>
<tr><td align="right">&nbsp;</td><td><input type="checkbox"
id="attachment3" name="attachment3" value="ITS Brief"<%if
session("ATTACHMENT3") = "ITS Brief" then Response.Write " checked"%>
onChange="setCookie('attachment3',this.value)"><a href="pdf/its.pdf"
target="_blank">ITS Brief</a></td><td align="center"></td></tr>
<tr><td align="right">&nbsp;</td><td><input type="checkbox"
id="attachment4" name="attachment4" value="TN Job Skills"<%if
session("ATTACHMENT4") = "TN Job Skills" then Response.Write " checked"%>
onChange="setCookie('attachment4',this.value)"><a href="pdf/jobskills.pdf"
target="_blank">TN Job Skills</a></td><td align="center"></td></tr>
<tr><td align="right">&nbsp;</td><td><input type="checkbox"
id="attachment5" name="attachment5" value="Japanese Schools"<%if
session("ATTACHMENT5") = "Japanese Schools" then Response.Write " checked"%>
onChange="setCookie('attachment5',this.value)"><a href="pdf/schools_japan.pdf"
target="_blank">Japanese Schools</a></td><td align="center"></td></tr>
<tr><td align="right">&nbsp;</td><td><input type="checkbox"
id="attachment6" name="attachment6" value="TN Meiji Gakuin School"<%if
session("ATTACHMENT6") = "TN Meiji Gakuin School" then Response.Write "
checked"%> onChange="setCookie('attachment6',this.value)"><a
href="pdf/meijigakuin.pdf" target="_blank">TN Meiji Gakuin School</a></td><td
align="center"></td></tr>
<tr><td align="right">&nbsp;</td><td><textarea id="other"
name="other" rows=5 cols=50 onBlur="setCookie('other',this.value)"><%if
session("OTHER") <> "" then Response.Write
session("OTHER")%></textarea></td><td align="center" valign="bottom"><input
type="button" value="Finished" id=submit2 name=submit2
onClick="finishButton()"> * <input type="button" name="delete1" id="delete1"
value="Delete" onClick="deletePkg()"><br><br><input type="button"
value="Abort/Return to Main" id=abort1 name=abort1
onClick="abortPkg2()"></td></tr>
</table>
</td></tr></table>
<input type="hidden" name="process" id="process" value="complete">
<input type="hidden" name="source" id="source" value="">
<input type="hidden" name="sel_num" id="sel_num" value="">
</form>
<script>getMyCookie();</script>
</body>
</html>



More information about the thelist mailing list