How to handle case-sensitivity of cookie?

Discussion in 'Javascript' started by kelvlam, Aug 21, 2006.

  1. kelvlam

    kelvlam Guest

    Hello all,

    I'm still a bit new with JavaScript, and I hope the guru here can shed
    some light for me. It's regarding handling cookie and the
    case-sensitive nature of JavaScript itself.

    My problem is how do I handle the "path" parameter in cookie.

    First, the sequence start at
    http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
    that page.

    Then, the following page, somehow change the case on the path, such as
    http://www.testServer1.com/testApp/page2.htm. Now in this page, I
    cannot access to the cookie that's set at the first initial page.

    Is there anyway to handle this kind of scenario? I hope I'm explaining
    the problem correctly.

    Thank you in advance.
    Kelvin
    kelvlam, Aug 21, 2006
    #1
    1. Advertising

  2. kelvlam

    Benjamin Guest

    Why does the TestApp directory have to change caps?
    kelvlam wrote:
    > Hello all,
    >
    > I'm still a bit new with JavaScript, and I hope the guru here can shed
    > some light for me. It's regarding handling cookie and the
    > case-sensitive nature of JavaScript itself.
    >
    > My problem is how do I handle the "path" parameter in cookie.
    >
    > First, the sequence start at
    > http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
    > that page.
    >
    > Then, the following page, somehow change the case on the path, such as
    > http://www.testServer1.com/testApp/page2.htm. Now in this page, I
    > cannot access to the cookie that's set at the first initial page.
    >
    > Is there anyway to handle this kind of scenario? I hope I'm explaining
    > the problem correctly.
    >
    > Thank you in advance.
    > Kelvin
    Benjamin, Aug 21, 2006
    #2
    1. Advertising

  3. kelvlam

    Randy Webb Guest

    kelvlam said the following on 8/21/2006 2:20 PM:
    > Hello all,
    >
    > I'm still a bit new with JavaScript, and I hope the guru here can shed
    > some light for me. It's regarding handling cookie and the
    > case-sensitive nature of JavaScript itself.
    >
    > My problem is how do I handle the "path" parameter in cookie.
    >
    > First, the sequence start at
    > http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
    > that page.
    >
    > Then, the following page, somehow change the case on the path, such as
    > http://www.testServer1.com/testApp/page2.htm. Now in this page, I
    > cannot access to the cookie that's set at the first initial page.
    >
    > Is there anyway to handle this kind of scenario? I hope I'm explaining
    > the problem correctly.


    Set it to lower case, then test it.

    cookieString.toLowerCase()

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Aug 21, 2006
    #3
  4. kelvlam

    kelvlam Guest

    Randy Webb wrote:
    > kelvlam said the following on 8/21/2006 2:20 PM:
    > > Hello all,
    > >
    > > I'm still a bit new with JavaScript, and I hope the guru here can shed
    > > some light for me. It's regarding handling cookie and the
    > > case-sensitive nature of JavaScript itself.
    > >
    > > My problem is how do I handle the "path" parameter in cookie.
    > >
    > > First, the sequence start at
    > > http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
    > > that page.
    > >
    > > Then, the following page, somehow change the case on the path, such as
    > > http://www.testServer1.com/testApp/page2.htm. Now in this page, I
    > > cannot access to the cookie that's set at the first initial page.
    > >
    > > Is there anyway to handle this kind of scenario? I hope I'm explaining
    > > the problem correctly.

    >
    > Set it to lower case, then test it.
    >
    > cookieString.toLowerCase()
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


    So should I be doing toLowercase both when setting and getting?

    i.e. document.cookie = cookieStr.toLowerCase();

    and for my get, I should just set the search parameter to
    param.toLowerCase() and then do the string comparison?



    I want to elaborate a little bit more of why I'm asking this question
    also, and give some precious description of my problem.

    The problem is I have no control of how a client browser access my web
    site. They could be coming in as "http://www.testAbc.com/site1", or
    they can be coming in as "http://www.testAbc.com/SiTe1". The site's
    Index.htm page then redirect the incoming request, to a internal ISAPI
    call on the IIS server.

    For example when a client come in from the browser as
    "http://www.testAbc.com/SiTe1", all cookies created will be only be
    accessible for pages that contain "http://www.testAbc.com/SiTe1" in the
    window.location property, correct? Since all my pages are generated
    dynamically by the ISAPI DLL, the window.location property could be
    change without my notice... and if the page somehow got
    "http://www.testAbc.com/site1" stored in the window.location property,
    then I won't be able to access the cookie that I intended to.

    Sorry for my very broken English. It's really hard to try to explain
    technical detail when I have still a fairly limited understanding of
    JavaScript. I hope I didn't confuse the original problem...

    Much appreciate for the help in advance.

    --
    Kelvin
    kelvlam, Aug 21, 2006
    #4
  5. kelvlam

    kelvlam Guest

    kelvlam wrote:
    > Randy Webb wrote:
    > > kelvlam said the following on 8/21/2006 2:20 PM:
    > > > Hello all,
    > > >
    > > > I'm still a bit new with JavaScript, and I hope the guru here can shed
    > > > some light for me. It's regarding handling cookie and the
    > > > case-sensitive nature of JavaScript itself.
    > > >
    > > > My problem is how do I handle the "path" parameter in cookie.
    > > >
    > > > First, the sequence start at
    > > > http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
    > > > that page.
    > > >
    > > > Then, the following page, somehow change the case on the path, such as
    > > > http://www.testServer1.com/testApp/page2.htm. Now in this page, I
    > > > cannot access to the cookie that's set at the first initial page.
    > > >
    > > > Is there anyway to handle this kind of scenario? I hope I'm explaining
    > > > the problem correctly.

    > >
    > > Set it to lower case, then test it.
    > >
    > > cookieString.toLowerCase()
    > >
    > > --
    > > Randy
    > > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    >
    > So should I be doing toLowercase both when setting and getting?
    >
    > i.e. document.cookie = cookieStr.toLowerCase();
    >
    > and for my get, I should just set the search parameter to
    > param.toLowerCase() and then do the string comparison?
    >
    >
    >
    > I want to elaborate a little bit more of why I'm asking this question
    > also, and give some precious description of my problem.
    >
    > The problem is I have no control of how a client browser access my web
    > site. They could be coming in as "http://www.testAbc.com/site1", or
    > they can be coming in as "http://www.testAbc.com/SiTe1". The site's
    > Index.htm page then redirect the incoming request, to a internal ISAPI
    > call on the IIS server.
    >
    > For example when a client come in from the browser as
    > "http://www.testAbc.com/SiTe1", all cookies created will be only be
    > accessible for pages that contain "http://www.testAbc.com/SiTe1" in the
    > window.location property, correct? Since all my pages are generated
    > dynamically by the ISAPI DLL, the window.location property could be
    > change without my notice... and if the page somehow got
    > "http://www.testAbc.com/site1" stored in the window.location property,
    > then I won't be able to access the cookie that I intended to.
    >
    > Sorry for my very broken English. It's really hard to try to explain
    > technical detail when I have still a fairly limited understanding of
    > JavaScript. I hope I didn't confuse the original problem...
    >
    > Much appreciate for the help in advance.
    >
    > --
    > Kelvin


    I would like to point out, I've been using these common utilities
    function as well, for handling my cookie within the pages. Maybe I can
    tweak these utility functions to solve my problem?

    <pre>
    /**
    * Sets a Cookie with the given name and value.
    *
    * name Name of the cookie
    * value Value of the cookie
    * [expires] Expiration date of the cookie (default: end of current
    session)
    * [path] Path where the cookie is valid (default: path of calling
    document)
    * [domain] Domain where the cookie is valid (default: domain of
    calling document)
    * [secure] Boolean value indicating if the cookie transmission
    requires a secure transmission
    */
    function setCookie(name, value, expires, path, domain, secure) {
    var cookieStr;
    cookieStr = name + "=" + escape(value);
    cookieStr += ((expires) ? "; expires=" + expires.toGMTString() : "");
    cookieStr += ((path) ? "; path=" + path : "");
    cookieStr += ((domain) ? "; domain=" + domain : "");
    cookieStr += ((secure) ? "; secure" : "");
    document.cookie = cookieStr;
    }
    /**
    * Gets the value of the specified cookie.
    *
    * name Name of the desired cookie.
    *
    * Returns a string containing value of specified cookie,
    * or null if cookie does not exist.
    */
    function getCookie(name) {
    var dc = document.cookie;
    var prefix = name.toLowerCase() + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
    } else {
    begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
    end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
    }
    /**
    * Deletes the specified cookie.
    *
    * name name of the cookie
    * [path] path of the cookie (must be same as path used to create
    cookie)
    * [domain] domain of the cookie (must be same as domain used to create
    cookie)
    */
    function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
    var cookieStr;
    cookieStr = name.toLowerCase() + "=";
    cookieStr += ((path) ? "; path=" + path : ""); //defaultPath);
    cookieStr += ((domain) ? "; domain=" + domain : "");
    cookieStr += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    document.cookie = cookieStr;
    }
    }
    </pre>
    kelvlam, Aug 21, 2006
    #5
  6. kelvlam

    Guest

    Good info. I will be in touch.
    kelvlam wrote:
    > kelvlam wrote:
    > > Randy Webb wrote:
    > > > kelvlam said the following on 8/21/2006 2:20 PM:
    > > > > Hello all,
    > > > >
    > > > > I'm still a bit new with JavaScript, and I hope the guru here can shed
    > > > > some light for me. It's regarding handling cookie and the
    > > > > case-sensitive nature of JavaScript itself.
    > > > >
    > > > > My problem is how do I handle the "path" parameter in cookie.
    > > > >
    > > > > First, the sequence start at
    > > > > http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
    > > > > that page.
    > > > >
    > > > > Then, the following page, somehow change the case on the path, such as
    > > > > http://www.testServer1.com/testApp/page2.htm. Now in this page, I
    > > > > cannot access to the cookie that's set at the first initial page.
    > > > >
    > > > > Is there anyway to handle this kind of scenario? I hope I'm explaining
    > > > > the problem correctly.
    > > >
    > > > Set it to lower case, then test it.
    > > >
    > > > cookieString.toLowerCase()
    > > >
    > > > --
    > > > Randy
    > > > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > > > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    > >
    > > So should I be doing toLowercase both when setting and getting?
    > >
    > > i.e. document.cookie = cookieStr.toLowerCase();
    > >
    > > and for my get, I should just set the search parameter to
    > > param.toLowerCase() and then do the string comparison?
    > >
    > >
    > >
    > > I want to elaborate a little bit more of why I'm asking this question
    > > also, and give some precious description of my problem.
    > >
    > > The problem is I have no control of how a client browser access my web
    > > site. They could be coming in as "http://www.testAbc.com/site1", or
    > > they can be coming in as "http://www.testAbc.com/SiTe1". The site's
    > > Index.htm page then redirect the incoming request, to a internal ISAPI
    > > call on the IIS server.
    > >
    > > For example when a client come in from the browser as
    > > "http://www.testAbc.com/SiTe1", all cookies created will be only be
    > > accessible for pages that contain "http://www.testAbc.com/SiTe1" in the
    > > window.location property, correct? Since all my pages are generated
    > > dynamically by the ISAPI DLL, the window.location property could be
    > > change without my notice... and if the page somehow got
    > > "http://www.testAbc.com/site1" stored in the window.location property,
    > > then I won't be able to access the cookie that I intended to.
    > >
    > > Sorry for my very broken English. It's really hard to try to explain
    > > technical detail when I have still a fairly limited understanding of
    > > JavaScript. I hope I didn't confuse the original problem...
    > >
    > > Much appreciate for the help in advance.
    > >
    > > --
    > > Kelvin

    >
    > I would like to point out, I've been using these common utilities
    > function as well, for handling my cookie within the pages. Maybe I can
    > tweak these utility functions to solve my problem?
    >
    > <pre>
    > /**
    > * Sets a Cookie with the given name and value.
    > *
    > * name Name of the cookie
    > * value Value of the cookie
    > * [expires] Expiration date of the cookie (default: end of current
    > session)
    > * [path] Path where the cookie is valid (default: path of calling
    > document)
    > * [domain] Domain where the cookie is valid (default: domain of
    > calling document)
    > * [secure] Boolean value indicating if the cookie transmission
    > requires a secure transmission
    > */
    > function setCookie(name, value, expires, path, domain, secure) {
    > var cookieStr;
    > cookieStr = name + "=" + escape(value);
    > cookieStr += ((expires) ? "; expires=" + expires.toGMTString() : "");
    > cookieStr += ((path) ? "; path=" + path : "");
    > cookieStr += ((domain) ? "; domain=" + domain : "");
    > cookieStr += ((secure) ? "; secure" : "");
    > document.cookie = cookieStr;
    > }
    > /**
    > * Gets the value of the specified cookie.
    > *
    > * name Name of the desired cookie.
    > *
    > * Returns a string containing value of specified cookie,
    > * or null if cookie does not exist.
    > */
    > function getCookie(name) {
    > var dc = document.cookie;
    > var prefix = name.toLowerCase() + "=";
    > var begin = dc.indexOf("; " + prefix);
    > if (begin == -1) {
    > begin = dc.indexOf(prefix);
    > if (begin != 0) return null;
    > } else {
    > begin += 2;
    > }
    > var end = document.cookie.indexOf(";", begin);
    > if (end == -1) {
    > end = dc.length;
    > }
    > return unescape(dc.substring(begin + prefix.length, end));
    > }
    > /**
    > * Deletes the specified cookie.
    > *
    > * name name of the cookie
    > * [path] path of the cookie (must be same as path used to create
    > cookie)
    > * [domain] domain of the cookie (must be same as domain used to create
    > cookie)
    > */
    > function deleteCookie(name, path, domain) {
    > if (getCookie(name)) {
    > var cookieStr;
    > cookieStr = name.toLowerCase() + "=";
    > cookieStr += ((path) ? "; path=" + path : ""); //defaultPath);
    > cookieStr += ((domain) ? "; domain=" + domain : "");
    > cookieStr += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    > document.cookie = cookieStr;
    > }
    > }
    > </pre>
    , Sep 8, 2006
    #6
  7. kelvlam

    Guest

    kelvlam wrote:
    > kelvlam wrote:
    > > Randy Webb wrote:
    > > > kelvlam said the following on 8/21/2006 2:20 PM:
    > > > > Hello all,
    > > > >
    > > > > I'm still a bit new with JavaScript, and I hope the guru here can shed
    > > > > some light for me. It's regarding handling cookie and the
    > > > > case-sensitive nature of JavaScript itself.
    > > > >
    > > > > My problem is how do I handle the "path" parameter in cookie.
    > > > >
    > > > > First, the sequence start at
    > > > > http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
    > > > > that page.
    > > > >
    > > > > Then, the following page, somehow change the case on the path, such as
    > > > > http://www.testServer1.com/testApp/page2.htm. Now in this page, I
    > > > > cannot access to the cookie that's set at the first initial page.
    > > > >
    > > > > Is there anyway to handle this kind of scenario? I hope I'm explaining
    > > > > the problem correctly.
    > > >
    > > > Set it to lower case, then test it.
    > > >
    > > > cookieString.toLowerCase()
    > > >
    > > > --
    > > > Randy
    > > > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > > > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    > >
    > > So should I be doing toLowercase both when setting and getting?
    > >
    > > i.e. document.cookie = cookieStr.toLowerCase();
    > >
    > > and for my get, I should just set the search parameter to
    > > param.toLowerCase() and then do the string comparison?
    > >
    > >
    > >
    > > I want to elaborate a little bit more of why I'm asking this question
    > > also, and give some precious description of my problem.
    > >
    > > The problem is I have no control of how a client browser access my web
    > > site. They could be coming in as "http://www.testAbc.com/site1", or
    > > they can be coming in as "http://www.testAbc.com/SiTe1". The site's
    > > Index.htm page then redirect the incoming request, to a internal ISAPI
    > > call on the IIS server.
    > >
    > > For example when a client come in from the browser as
    > > "http://www.testAbc.com/SiTe1", all cookies created will be only be
    > > accessible for pages that contain "http://www.testAbc.com/SiTe1" in the
    > > window.location property, correct? Since all my pages are generated
    > > dynamically by the ISAPI DLL, the window.location property could be
    > > change without my notice... and if the page somehow got
    > > "http://www.testAbc.com/site1" stored in the window.location property,
    > > then I won't be able to access the cookie that I intended to.
    > >
    > > Sorry for my very broken English. It's really hard to try to explain
    > > technical detail when I have still a fairly limited understanding of
    > > JavaScript. I hope I didn't confuse the original problem...
    > >
    > > Much appreciate for the help in advance.
    > >
    > > --
    > > Kelvin

    >
    > I would like to point out, I've been using these common utilities
    > function as well, for handling my cookie within the pages. Maybe I can
    > tweak these utility functions to solve my problem?
    >
    > <pre>
    > /**
    > * Sets a Cookie with the given name and value.
    > *
    > * name Name of the cookie
    > * value Value of the cookie
    > * [expires] Expiration date of the cookie (default: end of current
    > session)
    > * [path] Path where the cookie is valid (default: path of calling
    > document)
    > * [domain] Domain where the cookie is valid (default: domain of
    > calling document)
    > * [secure] Boolean value indicating if the cookie transmission
    > requires a secure transmission
    > */
    > function setCookie(name, value, expires, path, domain, secure) {
    > var cookieStr;
    > cookieStr = name + "=" + escape(value);
    > cookieStr += ((expires) ? "; expires=" + expires.toGMTString() : "");
    > cookieStr += ((path) ? "; path=" + path : "");
    > cookieStr += ((domain) ? "; domain=" + domain : "");
    > cookieStr += ((secure) ? "; secure" : "");
    > document.cookie = cookieStr;
    > }
    > /**
    > * Gets the value of the specified cookie.
    > *
    > * name Name of the desired cookie.
    > *
    > * Returns a string containing value of specified cookie,
    > * or null if cookie does not exist.
    > */
    > function getCookie(name) {
    > var dc = document.cookie;
    > var prefix = name.toLowerCase() + "=";
    > var begin = dc.indexOf("; " + prefix);
    > if (begin == -1) {
    > begin = dc.indexOf(prefix);
    > if (begin != 0) return null;
    > } else {
    > begin += 2;
    > }
    > var end = document.cookie.indexOf(";", begin);
    > if (end == -1) {
    > end = dc.length;
    > }
    > return unescape(dc.substring(begin + prefix.length, end));
    > }
    > /**
    > * Deletes the specified cookie.
    > *
    > * name name of the cookie
    > * [path] path of the cookie (must be same as path used to create
    > cookie)
    > * [domain] domain of the cookie (must be same as domain used to create
    > cookie)
    > */
    > function deleteCookie(name, path, domain) {
    > if (getCookie(name)) {
    > var cookieStr;
    > cookieStr = name.toLowerCase() + "=";
    > cookieStr += ((path) ? "; path=" + path : ""); //defaultPath);
    > cookieStr += ((domain) ? "; domain=" + domain : "");
    > cookieStr += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    > document.cookie = cookieStr;
    > }
    > }
    > </pre>
    , Sep 8, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry Whitehouse
    Replies:
    0
    Views:
    298
    Harry Whitehouse
    Sep 15, 2004
  2. Replies:
    0
    Views:
    460
  3. Kev
    Replies:
    15
    Views:
    842
    Lunchbox G4
    Jan 3, 2005
  4. Roy Schestowitz

    Case Sensitivity in Linux Server

    Roy Schestowitz, Mar 23, 2005, in forum: HTML
    Replies:
    10
    Views:
    745
    Roy Schestowitz
    Mar 24, 2005
  5. asqui
    Replies:
    0
    Views:
    252
    asqui
    Aug 17, 2004
Loading...

Share This Page