SV: SV: SV: [PHP] Send a cookie with a file_get_contents( ) request?
| From: | Anders Norrbring | Date: | Sun, 10 Aug 2008 09:01:14 +0000 |
| Subject: | SV: SV: SV: [PHP] Send a cookie with a file_get_contents( ) request? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-277948@lists.php.net to get a copy of this message | ||
> -----Ursprungligt meddelande-----
> Från: Jim Lucas [mailto:lists@cmsws.com]
> Skickat: den 10 augusti 2008 10:56
> Till: Anders Norrbring
> Kopia: 'Per Jessen'; php-general@lists.php.net
> Ämne: Re: SV: SV: [PHP] Send a cookie with a file_get_contents( )
> request?
>
> Anders Norrbring wrote:
> >> Anders Norrbring wrote:
> >>
> >>> Thanks Per,
> >>> I think so too, I glanced it, but unfortunately I have no idea
> >>> whatsoever about *how* to do it... So, if anyone have suggestions,
> or
> >>> concrete examples, please do share!
> >>>
> >>> Anders.
> >> I did play around with it once, but I don't have any actual code to
> >> share. Try this though:
> >>
> >> $opts = array(
> >> 'http'=>array(
> >> 'method'=>"GET",
> >> 'header'=>"Accept-language: en\r\n".
> >> "Cookie: foo=bar\r\n"
> >> )
> >> );
> >>
> >> $context = stream_context_create($opts);
> >>
> >> $result=file_get_contents( <url>, FILE_TEXT, $context );
> >>
> >>
> >> /Per Jessen, Zürich
> >
> >
> > I'm doing just that now.. ;-)
> > However, I have 3 parameters set in the cookie, so the question is
> how to include them all three...
> > Should I repeat the "Cookie: foo=bar\r\n" three times, like:
> >
> > "Cookie: foo=bar\r\n" .
> > "Cookie: bar=else\r\n" .
> > "Cookie: time=number\r\n"
> >
> > Or would I, in some way, add all three on one "Cookie:" line? If so,
> how do I delimit them? I haven't been doing much with http headers, so
> all of this is pure experimenting for me..
> >
> > Anders.
> >
> >
>
> If I recall correctly, you have to have them encoded, plus use a semi-
> colon to separate them. So
> something like this.
>
> "Cookie: foo=bar; bar=else; time=number\r\n";
>
> Check out the RFC for it.
> http://www.w3.org/Protocols/rfc2109/rfc2109.txt
>
> Look at section 5.1, example #7. That should answer your question(s)
> about cookies.
Thanks!
Actually, I found that just at the same time as your reply went into the mailbox.. ;-)
I'll do a test to see if I can get it right..
Thanks a lot to you all!
Anders.