how to generate a cookie in text file
I'm wondering if it's possible to generate a cookie and save it in a text file. The requirement is to generate a cookie for any domain not only that you own. After all the cookies are plain text but the "space" and path ("/") seems to make it a bit tricky to reproduce using manual programming (e.g not setcookie function ). Netscape seems to help but not I c开发者_如何学运维an't find a proof of concept shell/application to actually generate the cookie (not to get/receive/read it as curl does) http://curl.haxx.se/rfc/cookie_spec.html Basically I'm looking for a code snippet to see how this black magic works because I don't understand the spaces between the parameters . So far I identified the parameters required to generate a "valid" cookie .
Name
Content
Host
Path
Secure(true or false)
HTTP only(true or false)
Expires(optional)
Of course it is possible, all the major browser software does it.
Update:
cUrl apparently uses the Mozilla/Firefox cookie format for permanent (not session) cookies. Here is a good blog article describing that format. Writing it should be simply a matter of writing a text file in this format.
Simple code can be this:
$domain = '.go.com';
$expire = time() + 3600;
$name = 'fruit';
$value = 'apple';
file_put_contents($cookieJar, "\n$domain\tTRUE\t/\tFALSE\t$expire\t$name\t$value", FILE_APPEND);
But for advanced, This library allows you to manipulate (add, delete, update,...) Netscape Cookie File (eg. Cookies generated by CURL) :
https://github.com/kegi/netscape-cookie-file-handler
精彩评论