Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Answer: How can I send a cookie as part of an HTTP request?

by cei (Monk)
on Dec 25, 2000 at 05:26 UTC ( #48216=categorized answer: print w/replies, xml ) Need Help??

Q&A > HTTP and FTP clients > How can I send a cookie as part of an HTTP request? - Answer contributed by cei

Keep in mind that you can only set cookies for your own domain. If your get($url) is pulling from someone else's machine, and you're wanting to pre-login to that machine by making a cookie for it, it won't work. On the other hand, if you want to use the cookie to keep track of where someone is on your site before pulling contents from another site, that should work fine.

I use CGI.pm for my cookie handling.

  • Comment on Answer: How can I send a cookie as part of an HTTP request?
Replies are listed 'Best First'.
Re: Answer: How can I send a cookie as part of an HTTP request?
by chipmunk (Parson) on Dec 25, 2000 at 10:48 UTC
    Actually, you can specify a cookie that gets sent to another domain. That's what the 'domain' parameter in CGI's cookie method is for. (If it's not specified, the default domain is the originating domain.)

    Note, however, that browsers often have three settings for cookies; all cookies accepted, all cookies rejected, and cookies accepted except for cookies that aren't returned to the originating domain.

    All that is irrelevant to the current question, of course; using LWP's get() method, you can send whatever cookies you want with the request.

      Uhh, no that is exactly wrong. Clients are expected to ignore cookies that don't come from matching domains. If you request a resource from xxx.yyyy.com then the server that responds can set cookies for *.yyyy.com or xxx.yyyy.com but nothing else. What you are mixing in is the protection against you going to "http://www.xxx.com/" and that page calling a resource from "http://www.eviladplace.com/ad/tracker" and you picking up a cookie from a site you didn't even know you visited.

      All the domain parameter is for is setting the depth into your own domain. That way a server at www.cs.xxx.edu can set one cookie for all *.xxx.edu and another at just *.cs.xxx.edu and one just for itself at www.cs.xxx.edu! If I could set cookies in the netscape.com domain for you from hostile.org you can be sure I would be... =)

      LWP is most certainly the right answer tho! Look at HTTP::Request's perldocs specifically

      --
      $you = new YOU;
      honk() if $you->love(perl)

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Discipulus]: if more than 3 go for named variables LA
[Lady_Aleena]: Discipulus, it is at 2 now, but with what I am thinking about, it could go to 3. However, only 1 is needed. The second and third are optional.
[shmem]: straight list or named parameters - that depends on whether (and how many) optional arguments you have
[Discipulus]: if so a plain list is ok, imho
[Lady_Aleena]: shmem, I already have the plugin installed, just not active.
[shmem]: if you have 1 optional argument, place that at the end of the list. If you have more, go for named parameters.
[Lady_Aleena]: 1 manditory, 2 optional.
[Discipulus]: my ($need,$opta,$optb ) = @_; .. if $opta..
[shmem]: all else leads to trouble, even if the third argument depends on the existence of the second. That may become brittle.
[Discipulus]: but if have case like subname(15,undef,3 ) maybe bettere named parameters

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-04-27 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (506 votes). Check out past polls.