Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Cookie set to IP number?

by filmo (Scribe)
on Nov 30, 2001 at 15:49 UTC ( #128608=categorized question: print w/replies, xml ) Need Help??
Contributed by filmo on Nov 30, 2001 at 15:49 UTC
Q&A  > CGI programming


Is it possible to set a cookie to an IP number instead of the usual i.e.
it doesn't seem to work for me.

Answer: Cookie set to IP number?
contributed by dws

Is it possible to set a cookie to an IP number instead of the usual

You might be able to set the cookie (that is, get some browser to accept and store it), but no browser that I know of will actually return it to you. Where they to do so, it would introduce a massive security hole.

Think about it for a moment. It's possible to set a cookie for "" that will be returned by a browser for visits to "", "", or "". But what of ".1.1"? That would match sites all over the place.

Answer: Cookie set to IP number?
contributed by mt2k

You *can* set a cookie to an IP address.
You just cannot wildcard it! So while -domain=>'.' is invalid, -domain=>'' is not
(get rid of the period before the first set of numbers).

This has got to be allowed for one reason: what of servers that are located on a machine without a domain?
You have to be able to set cookies somehow!
Also, the only way to specify "subdomains" of an IP address is through port numbers.
It is apparently possible using HTTP::Cookie or the Set-Cookie2 header, but I have been unable to restrict a cookie to a specific port :(

Answer: Cookie set to IP number?
contributed by Fastolfe

By default, a cookie's Domain becomes the hostname of the URI used to make the HTTP request in the first place. If you connect to a web server by IP address, and this web server sets a cookie without a Domain attribute, the cookie will be implicitly set with the Domain equal to the IP address of the web server.

You cannot specify an IP address in the Domain portion of the cookie. In the first place, it's useless in the case where the IP address matches the IP address in the URI. Secondly, IP addresses do not easily follow organizational boundaries in the way DNS domains do. An IP address with a number one less or one greater than the IP address of the web server may not necessarily reside in the same organization. For security reasons, then, any form of wild-carding of IP addresses in the Domain attribute of a cookie is not permitted. This effectively removes the usefulness of the Domain attribute for any form of IP address, aside from the implicit use mentioned above.

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2020-11-25 03:00 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found