Send cookie to server?

Discussion in 'HTML' started by Martin, Mar 31, 2006.

  1. Martin

    Martin Guest

    How can I send a cookie (that was created by client-side scripting) to
    the server?

    It's my understanding that if the cookie had been created by the
    server, it would be automatically submitted when a request is sent to
    that server. Is it possible to achieve this same behavior with a
    cookie that was not created by the server?
     
    Martin, Mar 31, 2006
    #1
    1. Advertising

  2. Martin wrote:

    > How can I send a cookie (that was created by client-side scripting) to
    > the server?


    Issue any old http request, the browser will handle it automatically.

    > It's my understanding that if the cookie had been created by the
    > server, it would be automatically submitted when a request is sent to
    > that server. Is it possible to achieve this same behavior with a
    > cookie that was not created by the server?


    A cookie, is a cookie, is a cookie. It doesn't matter how it was created.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Mar 31, 2006
    #2
    1. Advertising

  3. Martin

    Martin Guest

    On Fri, 31 Mar 2006 18:36:28 +0100, David Dorward <>
    wrote:

    >Martin wrote:
    >
    >> How can I send a cookie (that was created by client-side scripting) to
    >> the server?

    >
    >Issue any old http request, the browser will handle it automatically.
    >
    >> It's my understanding that if the cookie had been created by the
    >> server, it would be automatically submitted when a request is sent to
    >> that server. Is it possible to achieve this same behavior with a
    >> cookie that was not created by the server?

    >
    >A cookie, is a cookie, is a cookie. It doesn't matter how it was created.


    David:

    Thank you, thank you, thank you. I have struggled with this for
    several hours. It never dawned on me to simply check the cookies
    collection on the server to see what was coming in.

    Now, please educate me about something: how does the browser know
    which cookies to send? Is it going to be sending those
    client-side-created-cookies to every server that the user goes to from
    now on?

    Martin
     
    Martin, Mar 31, 2006
    #3
  4. Martin wrote:

    > How can I send a cookie (that was created by client-side scripting) to
    > the server?
    >
    > It's my understanding that if the cookie had been created by the
    > server, it would be automatically submitted when a request is sent to
    > that server. Is it possible to achieve this same behavior with a
    > cookie that was not created by the server?


    The cookie gets sent to the server (on subsequent requests), which sent the
    document. You may have to specify the 'path' parameter (which defaults to
    the directory of the document), if the document is in a subdirectory and
    the cookie should be sent to documents in another directory. E.g. cookie
    created in /foo/doc1 and /bar/doc2 should recieve it. By default only
    documents in /foo will get the cookie.
    If you want the cookie to be sent to a document on another domain, you also
    have to specify the 'domain' parameter.

    document.cookie = 'foobar=this is the value; path=/; domain=www.example.com'

    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://pink.odahoda.de/
     
    Benjamin Niemann, Mar 31, 2006
    #4
  5. Martin wrote:

    > Now, please educate me about something: how does the browser know
    > which cookies to send? Is it going to be sending those
    > client-side-created-cookies to every server that the user goes to from
    > now on?


    Cookies are host name specific (although I believe there are means to state
    that they can be used on multiple hosts in the same domain).

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Mar 31, 2006
    #5
    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. Ben
    Replies:
    3
    Views:
    5,870
    Steven Cheng[MSFT]
    Jun 3, 2004
  2. Shapper

    Cookie and Session Cookie Questions.

    Shapper, Apr 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    580
  3. =?Utf-8?B?UGF1bA==?=

    Cookie Question (IP as domain and cookie file location)

    =?Utf-8?B?UGF1bA==?=, Jan 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,494
    Bruce Barker
    Jan 10, 2006
  4. ad
    Replies:
    2
    Views:
    7,537
    Kevin Spencer
    Jan 27, 2006
  5. =?Utf-8?B?TnVubw==?=

    Convert a PHP cookie to an ASP.NET cookie

    =?Utf-8?B?TnVubw==?=, Jan 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    446
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 31, 2006
Loading...

Share This Page