Link to home
Get AccessLog in
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
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Try to uncheck "automatic cookie handling" in IE properties
Avatar of dtiit
dtiit

ASKER

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
did you also tried to lower zone security for internet ? see if this helps
Avatar of dtiit

ASKER

...I did.   I played with all availalbe IE settings.  I did not dive into back end files or registry settings.
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 :)
Avatar of dtiit

ASKER


<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

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

Avatar of dtiit

ASKER

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
so next, did you check IE settings - temporary files "check with every visit" ?
Avatar of dtiit

ASKER

no dice, fails even with check at every visit
what about "normal' cookie setting ?

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

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of dtiit

ASKER

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