Retrieving Cookies

Discussion in 'Javascript' started by asg, May 15, 2006.

  1. asg

    asg Guest

    I have the code below that will retrieve a cookie that was placed by
    the server (ie: joes.com) that the document resides on. I want to be
    able to retrieve a cookie set by another server (ie: freds.com) but I
    want to retrieve it from a page served by joes.com. This code
    apparently using 'document.cookie' determines the server that the
    document resides on and looks for cookies from that server. Anybody
    know of code that will let you determine the server?

    var name = "cookie";
    function getCookie(name) {
    var cname = name + "=";
    var dc = document.cookie;

    if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
    begin += cname.length;
    end = dc.indexOf(";", begin);
    if (end == -1) end = dc.length;
    return unescape(dc.substring(begin,
    end));
    }
    }
    return null;
    }
    asg, May 15, 2006
    #1
    1. Advertising

  2. asg wrote:

    > I have the code below that will retrieve a cookie that was placed by
    > the server (ie: joes.com) that the document resides on. I want to be
    > able to retrieve a cookie set by another server (ie: freds.com) but I
    > want to retrieve it from a page served by joes.com.


    Not possible. If you could grab cookies from other domains the user has
    visited then you could gain access to those other domains with the user's
    credentials.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, May 15, 2006
    #2
    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. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,477
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,518
    Fredrik Lindner
    Nov 6, 2003
  3. _Who
    Replies:
    7
    Views:
    2,652
  4. Peter v.d. Berger

    Retrieving cookies from a webserver

    Peter v.d. Berger, Sep 26, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    70
    A. Sinan Unur
    Sep 27, 2004
  5. vipul
    Replies:
    2
    Views:
    104
    vipul
    Mar 28, 2008
Loading...

Share This Page