ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 29th, 2004, 10:56 PM
webmistress webmistress is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 webmistress User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Losing my cookies

I am designing an application that asks for a username (logon) on the first page and writes this onto the user's hard drive as a cookie. Then several asp pages later picks up the cookie and writes it into a database along with lots of other data that has been collected. It all works fine except when I use more than one pop-up window, then I lose the username. I even tried setting the expiration date of the cookie way in advance and I tried a session variable, but it still lost the username. I cannot figure out why.... can anyone help?

Reply With Quote
  #2  
Old January 30th, 2004, 06:47 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to dhouston
Glad you're not tossing your cookies, at least.

You might want to post a little code so some of the ASP weenies can take a look and diagnose the problem more readily.

Reply With Quote
  #3  
Old January 30th, 2004, 09:30 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 33 sec
Reputation Power: 10
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Yeah - you shouldn't be losing session vars - no matter where you use them... except of course in a different domain. Ditto w/ cookies. You can't use cookies/session var across domains.

Reply With Quote
  #4  
Old January 31st, 2004, 09:33 PM
webmistress webmistress is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 webmistress User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
On the login page I have this code to write the cookie...

Response.Cookies("UserName") = MM_valUserName

Then on the main data entry page I have several buttons that open pop-up windows opening different asp pages for the user to enter stuff. The user may open all these pop-ups or none. If none or one are opened and entered, then the username cookie is still there, but enter two or more...

Here is the code from the pop-up asp pages:
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<script language = "Javascript">
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	day=parseInt(strDay)
	month=parseInt(strMonth)	
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.FormT7.Date_T7_1
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

function confirmSubmission(){
if (confirm("Are you sure you want to submit this information?")){
return true;
}
else{
return false;
}
}

</script>
<%

Response.Cookies("T7")=request("T7")
Dim varT7
varT7 = request("T7") 

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/Intranet.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>T7 Data Entry</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<link href="http://10.0.0.60/intranet/Text.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
}
-->
</style></head>

<body>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td background="/Images/bg_top.gif"><img src="/Images/top_left2.jpg" width="179" height="72"></td>
    <td background="/Images/bg_top.gif"><div align="center"><img src="http://10.0.0.60/intranet/Images/top_logo.gif" width="340" height="72"></div></td>
    <td background="/Images/bg_top.gif"><div align="right"><img src="/Images/top_right2.jpg" width="179" height="72"></div></td>
  </tr>
  <tr>
    <td colspan="3"><table width="100%"  border="0">
      <tr bgcolor="#FFFFFF">
        <td width="25%" valign="top"><!-- InstanceBeginEditable name="Menu" --><!-- InstanceEndEditable --></td>
        <td width="75%"><!-- InstanceBeginEditable name="Main" -->
		
<%

If Request("submitT7") <> "Close and Save" then
%>


          <p>&nbsp;</p>
		  <form action="T7.asp" method="post" name="FormT7" onSubmit="return ValidateForm()">
          <table width="100%" border="0">
            <tr>
              <td colspan="4"> <h5> Total number of responses not within 2 hours for metro POD's  = <% Response.Write varT7 %></h5>			    </td>
              </tr>

<%
x=1
For x=1 to varT7
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.OpenDatabase("KPI_10.0.0.1", _
     "kpiuser/cindy", Cint(0))
Set OraDynaset = OraDatabase.DbCreateDynaset( _
    "select * from T_Reasons where question='T7' order by Reason", cint(0))
	fAttempt=Request.Cookies("T7Attempt_" & x)
%>

	 <tr> <td width="18%">Attempted Delivery :<br>
                  <% Select Case fAttempt
	   Case "Yes"  %>
			<input name="T7Attempt_<% response.write x%>" type="radio" value="Yes" checked>Yes
			<input name="T7Attempt_<% response.write x%>" type="radio" value="No">No
	<% Case "No"  %>
			<input name="T7Attempt_<% response.write x%>" type="radio" value="Yes">Yes
			<input name="T7Attempt_<% response.write x%>" type="radio" value="No" checked>No  
	<% Case Else  %>		  
			<input name="T7Attempt_<% response.write x%>" type="radio" value="Yes" unchecked>Yes
			<input name="T7Attempt_<% response.write x%>" type="radio" value="No" unchecked>No
	<% end select %></td>
              <td width="18%">Reason :<br>               
			  <select name="Reason_T7_<% response.write x %>">
				<option ><% If Request.Cookies("Reason_T7_" & x)<>"" Then Response.write Request.Cookies("Reason_T7_" & x) Else Response.write "Select Reason" end if %></option><% Do While(OraDynaset.EOF = FALSE) %><option value="<% = OraDynaset.Fields("Reason") %>"><% = OraDynaset.Fields("Reason") %></option>
<% OraDynaset.MoveNext 
Loop
%>
                </select></td>
              <td width="14%">Date (dd/mm/yyyy): 
               <% If Request.Cookies("Date_T7_" & x)<>"" Then
			  %>
			  <input name="Date_T7_<% response.write x%>" type="text" value="<%Response.write Request.Cookies("Date_T7_" & x)%>"> 
			  <% else %>
                <input name="Date_T7_<% response.write x%>" type="text">
				<% end if %>
			   </td>
              <td width="14%">Run Number :
			   <% If Request.Cookies("Run_T7_" & x)<>"" Then
			  %>
			  <input name="Run_T7_<% response.write x%>" type="text" value="<%Response.write Request.Cookies("Run_T7_" & x)%>"> 
			  <% else %>
                <input type="text" name="Run_T7_<% response.write x%>"></td>
              <% end if %>
                
              <td width="36%">&nbsp;</td>
            </tr>	
              <tr>
              <td colspan="4" valign="middle"><div align="left">
                <p>Other comments:<br>
				 <% If Request.Cookies("Comments_T7_" & x)<>"" Then
			  %>
			  <textarea name="Comments_T7_<% response.write x%>" cols="50" rows="2"><%Response.write Request.Cookies("Comments_T7_" & x)%></textarea>                    
					 <% else %>
					<textarea name="Comments_T7_<% response.write x%>" cols="50" rows="2"></textarea>
					 <% end if %>
            </p>
                <hr>
              </div></td>
              </tr>
            <tr>
              <td>&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
			  
<%
Next


 %> 
           		
            <tr>
              <td><input name="SubmitT7" type="submit" value="Close and Save" onclick="return confirm('Are you sure you want to submit information?')">
                </td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
          </table>
		  </form><input name="DiscardT7" type="submit" value="Close without saving" onclick="window.close()">
	<%
	else
		
	y=Request.Cookies("T7")
	x=1
For x=1 to y

	Response.Cookies("Reason_T7_" & x)=request("Reason_T7_" & x)
	Response.Cookies("Date_T7_" & x)=request("Date_T7_" & x)
	Response.Cookies("Run_T7_" & x)=request("Run_T7_" & x)
	Response.Cookies("T7Attempt_" & x)=request("T7Attempt_" & x)
	Response.Cookies("Comments_T7_" & x)=request("Comments_T7_" & x)
		next
%>
<SCRIPT LANGUAGE="JavaScript">
function closeWin(){
        window.close()
}
function timer(){
        timerID = setTimeout("closeWin()", 1000)
}

</SCRIPT>
Window will close in 1 second 
<script>
timer();
</script>
<%

		end if
		%> 
        <!-- InstanceEndEditable --></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>

Last edited by stumpy : February 1st, 2004 at 10:33 PM. Reason: Code not in code tags

Reply With Quote
  #5  
Old February 2nd, 2004, 06:59 AM
webmistress webmistress is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 webmistress User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
how to fix it?

I think I know what is wrong but don't know how to fix it. On opening and closing windows, I am getting different session id numbers. How can I keep one session id throughout?

Reply With Quote
  #6  
Old February 2nd, 2004, 07:23 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 33 sec
Reputation Power: 10
Send a message via ICQ to stumpy Send a message via MSN to stumpy
You shouldn't be getting different session id, unless you completely close a session (close all the browsers which were running the session (i.e. your site)). If you change domains, and come back, that too might also start a new session. Basically, if you leave the site, your session will change. Otherwise, something else is doing it... i'd double check your code again, as you are using an awful lot of cookies. (Too many for my liking - too difficult to manage and track)
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #7  
Old February 2nd, 2004, 06:16 PM
webmistress webmistress is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 webmistress User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What happends is from the main asp page I can open several other windows using buttons which open different asp pages. If I open say 2 of these windows, add data then close the windows it is fine, but if I open one of the same windows again to edit the data I already entered (hence the cookies) then it loses a previously entered cookie (even if I make it a persistent cookie) and I can see that it changes the session id.

Thanks in advance for any help guys. I am so stuck.

Reply With Quote
  #8  
Old February 9th, 2004, 09:59 AM
timmelton timmelton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 timmelton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cachine File size

I have whats sounds like the same problem. I found that increasing my temorary file cache size helped. I am still testing that but so far so good.

I had shut my temp file cache down to 64Meg on IE and 50 Megs on Mozilla. I have since increased both of them to 500megs and haven't had any trouble all mornging.

Tim


Quote:
Originally Posted by webmistress
What happends is from the main asp page I can open several other windows using buttons which open different asp pages. If I open say 2 of these windows, add data then close the windows it is fine, but if I open one of the same windows again to edit the data I already entered (hence the cookies) then it loses a previously entered cookie (even if I make it a persistent cookie) and I can see that it changes the session id.

Thanks in advance for any help guys. I am so stuck.

Reply With Quote
  #9  
Old February 9th, 2004, 04:32 PM
webmistress webmistress is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 webmistress User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I just increased my cache, but it made no difference. I am going to try to redesign the site

Thanks for the input.

Reply With Quote
  #10  
Old February 9th, 2004, 07:18 PM
timmelton timmelton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 timmelton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cache size

Yeah, I found later in the day that the problem was persisting. It did improve however.

our project is in Cold Fusion so we are switching to Client Variables that store in our MSSQL database. with ASP I have classically had to go with Session Vars instead of cookies.

so instead of Request.Cookies
just Session("mysessionvar")

That's in VBScript. You will need to lookup the exact Syntax for JScript. I see that your example declared vbscript as the main page language and then Jscript int the Script tag.

Session also likes to run server side.

Reply With Quote
  #11  
Old February 9th, 2004, 07:50 PM
webmistress webmistress is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 webmistress User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have started redesigning by putting all the variables on one page and using session("") and request("") - it works. Pity because now I have one extremely long page with lots if "If... else... end if" and code that is more difficult to debug. Takes a bit longer to load too.

Don't know if this will help you but I found this on MS site... might be worth a read...
PRB: Session Variables Do Not Persist Between Requests After You Install Internet Explorer Security Patch MS01-055
http://support.microsoft.com/defaul...kb;en-us;316112

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Losing my cookies


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek