Login   Register  
PHP Classes

Sending Cookies

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP HTTP protocol client  >  All threads  >  Sending Cookies  >  (Un) Subscribe thread alerts  
Subject:Sending Cookies
Summary:How do i send cookies with the request?
Author:Temel Nazli
Date:2011-02-24 18:38:47
Update:2011-02-25 18:27:55

  1. Sending Cookies   Reply  
Picture of Temel Nazli
Temel Nazli
2011-02-24 18:38:47
I would like to send few cookies with my GET or POST request.
Currently what i do is:

$http=new http_class;
$url="http://www.fbi.gov/fun-games/"; //worth visiting :)
$arguments[Headers]["Cookie"]="mycookie=bla bla bla; myothercookie=talking about the revolution; mylastcookie=i am the most delicious cookie here"
.......more code here.....

So i actually set the cookies manually by declaring them in the Request headers.

My question[s]:
is there a better way to do it? Is there a method for that?

Also, i could not find any info about the methods of the class. Could be great if someone case explain:
SetCookie($name, $value, $expires="" , $path="/" , $domain="" , $secure=0, $verbatim=0)
SaveCookies(&$cookies, $domain='', $secure_only=0, $persistent_only=0)
SavePersistentCookies(&$cookies, $domain='', $secure_only=0)
GetPersistentCookies(&$cookies, $domain='', $secure_only=0)
RestoreCookies($cookies, $clear=1)

Many Thanks!

  2. Re: Sending Cookies   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-02-24 23:01:07 - In reply to message 1 from Temel Nazli
Yes, proper documentation is still missing until now. Lets see if I can make some time to do it soon.

Meanwhile, you can use the SetCookie function to set specific cookie values.

  3. Re: Sending Cookies   Reply  
Picture of Temel Nazli
Temel Nazli
2011-02-25 08:48:00 - In reply to message 2 from Manuel Lemos
It is a bit odd - SetCookie function take arguments that are not related to its purpose.

If i understand right, SetCookie function purpose is to add a cookie to the GET or POST request that is about to be sent.
When you send a cookie with your request you do not need to specify any domain, exp. time or path - those values are not sent with the cookie, they are needed only for the client (browser).

Can you please write a very short description for each function that i mentioned?

Thank you once again for sharing the class and for supporting it.

  4. Re: Sending Cookies   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-02-25 18:27:55 - In reply to message 3 from Temel Nazli
No, all those parameters are necessary so the class knows on which requests which cookies should be sent and also when cookies should be discarded because they expire.

It is exactly like a browser as this class is also an HTTP client, like any browser.

What parameters you do not understand?