Avatar of dtiit
dtiit asked on

IE7 on WinXP Cookies Fail

All-
I'm running into a similar problem.  Cookies work on FireFix, Chrome, but not IE7 on Vista, and IE7 on SOME XP hosts.  

I've tried many different flavors of the setcookie sample code.   The cookie is being set and used from the root URI of the webapp.  It fails under both http/https.

~Todd
Web BrowsersJavaScriptScripting Languages

Avatar of undefined
Last Comment
dtiit

8/22/2022 - Mon
Lukasz Chmielewski

Try to uncheck "automatic cookie handling" in IE properties
ASKER
dtiit

unfortunately, that doesn't help.  I've tried this, I've also tried adding *.domain.com and host.domain.com to the sites list with ALLOW
Lukasz Chmielewski

did you also tried to lower zone security for internet ? see if this helps
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
dtiit

...I did.   I played with all availalbe IE settings.  I did not dive into back end files or registry settings.
Lukasz Chmielewski

could you paste the code of cookie setting ? sorry for my ignorance but I'm trying to figure it out step by step... a fresh look is all you need :)
ASKER
dtiit


<html>
<head>
 
<SCRIPT LANGUAGE = "JavaScript">
<!--
    //http://www.javascripter.net/faq/settinga.htm
    function SetCookie2(cookieName,cookieValue,nDays) {
     var today = new Date();
     var expire = new Date();
     if (nDays==null || nDays==0) nDays=1;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     document.cookie = cookieName+"="+escape(cookieValue)
                     + ";expires="+expire.toGMTString();
    }
 
		//http://www.javascripter.net/faq/readinga.htm
    function ReadCookie2(cookieName) {
     var theCookie=""+document.cookie;
     var ind=theCookie.indexOf(cookieName);
     if (ind==-1 || cookieName=="") return ""; 
     var ind1=theCookie.indexOf(';',ind);
     if (ind1==-1) ind1=theCookie.length; 
     return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
    }
    
    //http://techpatterns.com/downloads/javascript_cookies.php
    function Get_Cookie3( check_name ) {
      	// first we'll split this cookie up into name/value pairs
      	// note: document.cookie only returns name=value, not the other components
      	var a_all_cookies = document.cookie.split( ';' );
      	var a_temp_cookie = '';
      	var cookie_name = '';
      	var cookie_value = '';
      	var b_cookie_found = false; // set boolean t/f default f
      
      	for ( i = 0; i < a_all_cookies.length; i++ )
      	{
      		// now we'll split apart each name=value pair
      		a_temp_cookie = a_all_cookies[i].split( '=' );
      
      
      		// and trim left/right whitespace while we're at it
      		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
      
      		// if the extracted name matches passed check_name
      		if ( cookie_name == check_name )
      		{
      			b_cookie_found = true;
      			// we need to handle case where cookie has no value but exists (no = sign, that is):
      			if ( a_temp_cookie.length > 1 )
      			{
      				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
      			}
      			// note that in cases where cookie is initialized but no value, null is returned
      			return cookie_value;
      			break;
      		}
      		a_temp_cookie = null;
      		cookie_name = '';
      	}
      	if ( !b_cookie_found )
      	{
      		return null;
      	}
      }
 
//-->
</script>
 
<body>
<font face=tahoma>
 
<noscript>
JavaScript is turned off in your web browser. Turn it on to take full advantage of this site, then refresh the page.
</noscript>
 
<!-- Set Cookies -->
Preparing InfoView Login...
<SCRIPT language="javascript">
 
   SetCookie2('InfoViewSystemName','SERVERNAME','0);
   SetCookie2('InfoViewAuth', 'secWinAD', '0');
 
 
   //Check Cookie
   if ( Get_Cookie3( 'InfoViewSystemName' ) ) alert('cookie is set');
 
   // Query the current cookie values, for validation
   strCookie=document.cookie
   
   // Validate Cookie was created
   if (strCookie.indexOf("InfoView") < 0) {
    alert("Failed to Create Cookie, check security settings");
    document.write ("<HR><H2><FONT COLOR=RED>There was an issue creating a browser cookie<BR>Please confirm your settings permit cookies from this site</font></H2>");
    location.replace("fail.htm");
   }else{
	  <% if bVerbose then %>
    alert("Cookie Is Set! Redirecting...");
    <% End If %>
    location.replace("next.htm");
  }
  
</SCRIPT>
 
</body>
</html>

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Lukasz Chmielewski

maybe it does not matter at all but worth trying:

line 81:    
is
SetCookie2('InfoViewSystemName','SERVERNAME','0);
should be
SetCookie2('InfoViewSystemName','SERVERNAME','0');

line 97:
id write
document.location.replace("fail.htm");


also you use <% tags ASP (?) %>
try to temporarily delete them



and try with the code below
<html>
<head>
 
<SCRIPT LANGUAGE = "JavaScript">
<!--
    //http://www.javascripter.net/faq/settinga.htm
    function SetCookie2(cookieName,cookieValue,nDays) {
     var today = new Date();
     var expire = new Date();
     if (nDays==null || nDays==0) nDays=1;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     document.cookie = cookieName+"="+escape(cookieValue)
                     + ";expires="+expire.toGMTString();
    }
 
                //http://www.javascripter.net/faq/readinga.htm
    function ReadCookie2(cookieName) {
     var theCookie=""+document.cookie;
     var ind=theCookie.indexOf(cookieName);
     if (ind==-1 || cookieName=="") return ""; 
     var ind1=theCookie.indexOf(';',ind);
     if (ind1==-1) ind1=theCookie.length; 
     return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
    }
    
    //http://techpatterns.com/downloads/javascript_cookies.php
    function Get_Cookie3( check_name ) {
        // first we'll split this cookie up into name/value pairs
        // note: document.cookie only returns name=value, not the other components
        var a_all_cookies = document.cookie.split( ';' );
        var a_temp_cookie = '';
        var cookie_name = '';
        var cookie_value = '';
        var b_cookie_found = false; // set boolean t/f default f
      
        for ( i = 0; i < a_all_cookies.length; i++ )
        {
                // now we'll split apart each name=value pair
                a_temp_cookie = a_all_cookies[i].split( '=' );
      
      
                // and trim left/right whitespace while we're at it
                cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
      
                // if the extracted name matches passed check_name
                if ( cookie_name == check_name )
                {
                        b_cookie_found = true;
                        // we need to handle case where cookie has no value but exists (no = sign, that is):
                        if ( a_temp_cookie.length > 1 )
                        {
                                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
                        }
                        // note that in cases where cookie is initialized but no value, null is returned
                        return cookie_value;
                        break;
                }
                a_temp_cookie = null;
                cookie_name = '';
        }
        if ( !b_cookie_found )
        {
                return null;
        }
      }
 
//-->
</script>
 
<body>
<font face=tahoma>
 
<noscript>
JavaScript is turned off in your web browser. Turn it on to take full advantage of this site, then refresh the page.
</noscript>
 
<!-- Set Cookies -->
Preparing InfoView Login...
<SCRIPT language="javascript">
 
   SetCookie2('InfoViewSystemName','SERVERNAME','0');
   SetCookie2('InfoViewAuth', 'secWinAD', '0');
 
 
   //Check Cookie
   if ( Get_Cookie3( 'InfoViewSystemName' ) ) alert('cookie is set');
 
   // Query the current cookie values, for validation
   strCookie=document.cookie
   
   // Validate Cookie was created
   if (strCookie.indexOf("InfoView") < 0) {
    alert("Failed to Create Cookie, check security settings");
    document.write ("<HR><H2><FONT COLOR=RED>There was an issue creating a browser cookie<BR>Please confirm your settings permit cookies from this site</font></H2>");
    document.location.replace("fail.htm");
   }else{
 
    alert("Cookie Is Set! Redirecting...");
 
    location.replace("next.htm");
  }
  
</SCRIPT>
 
</body>
</html>

Open in new window

ASKER
dtiit

ok, the type-o's were my afault, the original page has the correct context, I goofed when I transposed it into this snippit.

This page is an ASP page, that is assembled server side with IIS, the values for SERVERNAME are determined server side, and passed back as ASP variables.

~Todd
Lukasz Chmielewski

so next, did you check IE settings - temporary files "check with every visit" ?
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
dtiit

no dice, fails even with check at every visit
Lukasz Chmielewski

what about "normal' cookie setting ?

<?php
if(setcookie("TestCookie", "test", time()+3600)) echo "cookie was set";
?>
ASKER CERTIFIED SOLUTION
Lukasz Chmielewski

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
dtiit

This is the final code that worked, its name is cookietest.ASP (active server pages).

Note that for some reason, I need to create "2" cookies for some reason, the "InfoViewSystemName" being the second.
<%
 dim strCookieValue
 strCookieValue = "COOKIE_WORKED" 
 %>
<HTML>
<HEAD>
<SCRIPT LANGUAGE = "JavaScript">
<!--
    //http://www.javascripter.net/faq/settinga.htm
    function SetCookie3(cookieName,cookieValue,nDays) {
     var today = new Date();
     var expire = new Date();
     if (nDays==null || nDays==0) nDays=1;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
    }
    //-->
</script>
</HEAD>
<BODY>
Testing Cookies...
<SCRIPT LANGUAGE = "JavaScript">
      SetCookie3('TEST','TESTVALUE','0');
      SetCookie3('InfoViewSystemName','<%=strCookieValue%>','0');
      alert(document.cookie);
      
</script>
</BODY>
</HTML>

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.