Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Location
    London, UK
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Restrictions on session only cookies

    Is it ok to have more than one session cookie on a page/site (obviously with different names)? Are there any restrictions on this or any special actions to take?

    I ask because I've one session cookie working perfectly, but the second one just doesn't want to work.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,095
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Yes there is a limit on cookies. I think all browsers limit them to 20 per domain.
    Some browsers IE, opera have a 4K limit on the total amount of space taken up.
    I'm sure you don't max this out with only two. Post code for the setting and reading of these cookies please.

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Location
    London, UK
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <script type="text/javascript">
    var min=12;
    var max=24;
    function zoomLetter(mysize) {
       var p = document.getElementsByTagName('p');
       for(i=0;i<p.length;i++) {
          if(p[i].style.fontSize) {
             var s = parseInt(p[i].style.fontSize.replace("px",""));
          } else if(mysize>2) {
    		  var s = mysize;
    	  }else{
             var s = 16;
          }
    	  if (mysize ==1){
          	if(s!=max) {
             s += 1;
          }
    	  }
    	   if (mysize ==-1){
    	   		if(s!=min) {
             		s -= 1;
          }
    	  }
    	  if (mysize >2){
    		  s=mysize;
    	  }
          p[i].style.fontSize = s+"px"
    	  }
    document.cookie="magnif="+s;
    }
    
     //Get cookie routine by Shelley Powers 
     function changeBGC(color){
    document.bgColor = color;
    document.cookie="bgcolor="+color;
     }
    function get_cookie(Name) {
     var search = Name + "="
     var returnvalue = "";
     if (document.cookie.length > 0) {
     offset = document.cookie.indexOf(search)
     // if cookie exists
     if (offset != -1) { 
    offset += search.length
     // set index of beginning of value
     end = document.cookie.indexOf(";", offset);
     // set index of end of cookie value
     if (end == -1) end = document.cookie.length;
     returnvalue=unescape(document.cookie.substring(offset, end))
     }
     }
     return returnvalue;
     }
    
    if (get_cookie("bgcolor")!="")
    changeBGC(get_cookie("bgcolor"))
    
    if (get_cookie("magnif")!="")
    zoomLetter(get_cookie("magnif"))
    
     </script> 
    
    
    </head>
     <body>
    <div id="topbox"><img src="WFDA-headerright.gif" width="574" height="291" alt="headerright" /></div>
    <div id="welcome">
     <p>Welcome<br /><br />
    Welcome to the Waltham Forest Dyslexia Association (WFDA).  We are a grassroots charity that has been running since 1989 set up by concerned individuals – both parents of children with dyslexia and by teachers that specialise in dyslexia. Although we are affiliated with the British Dyslexia   Associaiton (BDA) we are dependent on membership subscriptions, grants and fundraising.</p> </div>
    
    <div id="welcome2">
     <p>Our Vision<br /><br />
     WFDA is committed to sending out a lifeline to people with dyslexia who often have nowhere else to turn. Our vision is that we will live in a dyslexic friendly society that enables dyslexic people of all ages to reach their full potential. </p>
    </div>
    <div id="welcome3">
      <p>Our Aim <br /><br />
    To support the needs of dyslexic children, young people and adults by providing an accessible, affordable, quality service run by appropriately trained staff. Also to advance the education of dyslexic people of all ages to help them to improve their confidence and independence as well as their well-being.</p>
    </div>
    <div id="header"><img src="WFDA-header.gif" width="630" height="291" alt="WFDA logo" /></div>
    <div id="picture1">
     
    </div>
    <div id="background"><strong>Background colour</strong>
      <table width="307" border="0" align="center" cellpadding="2">
        <tr> <td width="13" bgcolor="#cccccc"><a href="#" onClick="javascript:changeBGC('#cccccc')">&nbsp;&nbsp; </a> </td>
           <td width="13" bgcolor="#ccccff"><a href="#" onClick="javascript:changeBGC('#ccccff')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ccffff"><a href="#" onClick="javascript:changeBGC('#ccffff')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#99ffcc"><a href="#" onClick="javascript:changeBGC('#99ffcc')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#3dffdd"><a href="#" onClick="javascript:changeBGC('#3dffdd')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#88dd00"><a href="#" onClick="javascript:changeBGC('#88dd00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ccff00"><a href="#" onClick="javascript:changeBGC('#ccff00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#eeee00"><a href="#" onClick="javascript:changeBGC('#eeee00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ffcc00"><a href="#" onClick="javascript:changeBGC('#ffcc00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#cc9999"><a href="#" onClick="javascript:changeBGC('#cc9999')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ff9999"><a href="#" onClick="javascript:changeBGC('#ff9999')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ff99ff"><a href="#" onClick="javascript:changeBGC('#ff99ff')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ffcccc"><a href="#" onClick="javascript:changeBGC('#ffcccc')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ffffbb"><a href="#" onClick="javascript:changeBGC('#ffffbb')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#FFFFFF"><a href="#" onClick="javascript:changeBGC('#FFFFFF')">&nbsp;&nbsp; </a></td>      
    </tr>
      </table>
      <table width="108" border="0"  align="center" cellpadding="2">
      <tr>
        <td width="50" height="49"> <h1 id="sprytrigger1"><a href="#" onclick="zoomLetter(1)">A+</a></h1></td>
        <td width="44"><h3 id="sprytrigger2"><a href="#" onclick="zoomLetter(-1)">A-</a></h3></td>
      </tr>
    </table>
    Both changeBGC and zoomLetter work within the page, but only the background colour is copied to another page when that's opened. The other page has the same script and zoomLetter works perfectly within that page.
    For clarification, zoomLetter allows the user to increase or decrease the font size, one px at a time, between 14 and 24px.

    I get the impression that either the cookie isn't stored or isn't called when the new page opens.
    Last edited by Henry.; 01-11-2013 at 04:35 AM. Reason: error in code..wasn't an error!

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,095
    Thanks
    23
    Thanked 594 Times in 593 Posts
    The first thing when loading a page is to look for the cookies. You could use:
    <body onload="checkCookie()">

    reading a cookie is not a straight foreword thing. read this http://www.w3schools.com/js/js_cookies.asp

    P.S. I used Firefox to check for the cookies and yours are set.

  • #5
    New to the CF scene
    Join Date
    Jan 2013
    Location
    London, UK
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    The first thing when loading a page is to look for the cookies. You could use:
    <body onload="checkCookie()">
    I tried that, thanks, but it still doesn't work

    Quote Originally Posted by sunfighter View Post
    reading a cookie is not a straight foreword thing. read this http://www.w3schools.com/js/js_cookies.asp
    This is where I got my information about session cookies from.
    http://www.javascriptkit.com/javatutors/cookie.shtml


    Quote Originally Posted by sunfighter View Post
    P.S. I used Firefox to check for the cookies and yours are set.
    Thanks for that, sunfighter.

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,095
    Thanks
    23
    Thanked 594 Times in 593 Posts
    zoomLetter(mysize) does not seem to be working so I just made up a value of 2 to get a cookie for it. Your functions to make a cookie are the top two functions. I then added the w3shools code for reading them. did a on load thing and instead of changing the font and bgcolor I just used an alert to show you what the cookies are set to.

    You can change the magnif to what ever you want to check it. But this is how it's done.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>New document</title>
    <script type="text/javascript">
    function zoomLetter(mysize) {
    document.cookie="magnif="+8;
    }
     function changeBGC(color){
    document.bgColor = color;
    document.cookie="bgcolor="+color;
     }
    
    /*AND NOW*/
    function getCookie(c_name)
    {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
      {
      x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
      y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
      x=x.replace(/^\s+|\s+$/g,"");
      if (x==c_name)
        {
        return unescape(y);
        }
      }
    }
    
    function setCookie(c_name,value,exdays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    }
    
    function checkCookie()
    {
    
    var magnify = getCookie("magnif");
    var thecolor = getCookie("bgcolor");
    if (magnify != null && magnify != "" && thecolor != null && thecolor != "")
    	alert("the magnify is "+magnify+" and the color is "+thecolor);
    }
    </script>
    <body onload="checkCookie()">
    
    <div id="topbox"><img src="WFDA-headerright.gif" width="574" height="291" alt="headerright" /></div>
    <div id="welcome">
     <p>Welcome<br /><br />
    Welcome to the Waltham Forest Dyslexia Association (WFDA).  We are a grassroots charity that has been running since 1989 set up by concerned individuals – both parents of children with dyslexia and by teachers that specialise in dyslexia. Although we are affiliated with the British Dyslexia   Associaiton (BDA) we are dependent on membership subscriptions, grants and fundraising.</p> </div>
    
    <div id="welcome2">
     <p>Our Vision<br /><br />
     WFDA is committed to sending out a lifeline to people with dyslexia who often have nowhere else to turn. Our vision is that we will live in a dyslexic friendly society that enables dyslexic people of all ages to reach their full potential. </p>
    </div>
    <div id="welcome3">
      <p>Our Aim <br /><br />
    To support the needs of dyslexic children, young people and adults by providing an accessible, affordable, quality service run by appropriately trained staff. Also to advance the education of dyslexic people of all ages to help them to improve their confidence and independence as well as their well-being.</p>
    </div>
    <div id="header"><img src="WFDA-header.gif" width="630" height="291" alt="WFDA logo" /></div>
    <div id="picture1">
    
    </div>
    <div id="background"><strong>Background colour</strong>
      <table width="307" border="0" align="center" cellpadding="2">
        <tr> <td width="13" bgcolor="#cccccc"><a href="#" onClick="javascript:changeBGC('#cccccc')">&nbsp;&nbsp; </a> </td>
           <td width="13" bgcolor="#ccccff"><a href="#" onClick="javascript:changeBGC('#ccccff')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ccffff"><a href="#" onClick="javascript:changeBGC('#ccffff')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#99ffcc"><a href="#" onClick="javascript:changeBGC('#99ffcc')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#3dffdd"><a href="#" onClick="javascript:changeBGC('#3dffdd')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#88dd00"><a href="#" onClick="javascript:changeBGC('#88dd00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ccff00"><a href="#" onClick="javascript:changeBGC('#ccff00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#eeee00"><a href="#" onClick="javascript:changeBGC('#eeee00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ffcc00"><a href="#" onClick="javascript:changeBGC('#ffcc00')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#cc9999"><a href="#" onClick="javascript:changeBGC('#cc9999')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ff9999"><a href="#" onClick="javascript:changeBGC('#ff9999')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ff99ff"><a href="#" onClick="javascript:changeBGC('#ff99ff')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ffcccc"><a href="#" onClick="javascript:changeBGC('#ffcccc')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#ffffbb"><a href="#" onClick="javascript:changeBGC('#ffffbb')">&nbsp;&nbsp; </a></td>
           <td width="13" bgcolor="#FFFFFF"><a href="#" onClick="javascript:changeBGC('#FFFFFF')">&nbsp;&nbsp; </a></td>
    </tr>
      </table>
      <table width="108" border="0"  align="center" cellpadding="2">
      <tr>
        <td width="50" height="49"> <h1 id="sprytrigger1"><a href="#" onclick="zoomLetter(1)">A+</a></h1></td>
        <td width="44"><h3 id="sprytrigger2"><a href="#" onclick="zoomLetter(-1)">A-</a></h3></td>
      </tr>
    </table>
    
    </body>
    </html>

  • Users who have thanked sunfighter for this post:

    Henry. (01-12-2013)

  • #7
    New to the CF scene
    Join Date
    Jan 2013
    Location
    London, UK
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks very much, sunfighter, that did the trick...after a couple of weeks of my struggling on my own.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •