Reading cookies from a specific host

Discussion in 'JavaScript' started by dexfantasy, Apr 26, 2006.

  1. #1
    Is there a way to only see cookies that have been set on a specific host (rather than domain)? For example, the institution I work for uses an LMS system called WebCT. There are multiple WebCT servers inside the same domain that set the same cookie name. Is there a way in Javascript to distinguish between the cookies set on the two servers? A script that parsed out only the cookies that have been set on the same host the script is running would be perfect--right now I'm getting a semicolon delimited list of cookies that set the same cookie name.

    Thanks for your help,

    dex
     
    dexfantasy, Apr 26, 2006 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    AFAIK, you can *only* access cookies for the same domain the script is on.
     
    exam, Apr 26, 2006 IP
  3. dexfantasy

    dexfantasy Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yep - unfortunately, this isn't enough to avoid conflicts with the two servers since they are both in the same domain.

    Actually... I think I figured out my problem. The cookie for the page you are currently on seems to always be listed later than previous cookies with the same name set on different servers.

    So... Never mind :)

    Thanks,

    Dex
     
    dexfantasy, Apr 26, 2006 IP
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Have the cookie name change for each host and only retrieve that cookie. If you haven't already found a workaround.
     
    exam, Apr 26, 2006 IP
  5. dexfantasy

    dexfantasy Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The cookie name cannot be changed because its set by webct... That's the problem.

    Basically, I was extracting the username of students who logged into their course by parsing a webct cookie, so that I can send it via AJAX to a remote server. Using the assumption that the current host's cookie will always be the last one listed in document.cookie, I was able to code around the issue... Hopefully this assumption is correct. So far, it seems to be working.

    Thanks.

    Matt
     
    dexfantasy, Apr 26, 2006 IP
  6. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well, it looks like you have a workaround. Hopefully that assumption is correct.
     
    exam, Apr 26, 2006 IP