以编程方式设置浏览器cookie(Firefox) [英] Programmatically set browser cookie (Firefox)
问题描述
我从这个问题知道,Firefox 3.0及更高版本将其cookie存储在SQLite数据库中。我的问题是:您是否可以通过其他桌面程序访问此数据库,从而添加cookie?
I know from this question that Firefox 3.0 and up stores its cookies in an SQLite database. My question is: can you access this database from other desktop programs in such a way that you could add a cookie?
我知道安全隐患。但是,我根本不想阅读它们。我希望能够设置一个cookie(如果可能)。我什至不想覆盖Cookie。我只想添加它(如果尚未添加)。
I realize this has security implications. However, I do not want to read them at all. I want to be able to set one cookie if possible. I don't even want to overwrite a cookie. I just want to add it if it isn't there already. This is sort of a personal project I'm working on for fun.
这个问题大部分与语言无关。我希望使用C#解决方案,但是用任何语言进行的概念验证就足够了。
This question is mostly language agnostic. I would prefer a solution in C#, but proof of concept in any language will suffice.
额外的功劳:在Internet Explorer中设置相同的cookie也很酷
Extra credit: It would be cool to set the same cookie in Internet Explorer, too
推荐答案
对于FF3,您可以使用任何SQLite包装器-但是,请检查FF是否正在运行-它可能正在写锁定文件(未经测试)。
For FF3, you can access the cookies.sqlite file with any SQLite wrapper - however, check whether FF is running - it may be write-locking the file (not tested).
数据库包含以下内容:
TABLE moz_cookies (
id INTEGER PRIMARY KEY,
name TEXT,
value TEXT,
host TEXT,
path TEXT,
expiry INTEGER,
lastAccessed INTEGER,
isSecure INTEGER,
isHttpOnly INTEGER
)
不确定主键,它看起来像是创建cookie的unix时间戳; expiry和lastAccessed也是unix时间戳,其余的不言自明。
Not sure about the primary key, it looks like it is a unix timestamp of when the cookie was created; expiry and lastAccessed are also unix timestamps, the rest is self-explanatory.
尝试将插入moz_cookies
并查看如果FF立即意识到新的cookie或是否需要重新启动。
Try an INSERT INTO moz_cookies
and see if FF becomes immediately aware of the new cookie or if it requires a restart.
这篇关于以编程方式设置浏览器cookie(Firefox)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!