MozillaZine

INSERT INTO moz_cookies is not correct?

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
BlackMatrix
 
Posts: 3
Joined: November 5th, 2013, 9:22 am

Post Posted November 5th, 2013, 1:13 pm

Good evening.

My Application makes some login request to some servers. I want to export theses cookies to cookies.sqlite. What do I have to do that Firefox accepts these cookies? Its not working yet.

I have created a database with a table:

Code: Select all
CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, appId, inBrowserElement))


and after that I try to insert the cookies with:

Code: Select all
INSERT INTO moz_cookies (id,name,value,path,baseDomain,host,expiry) VALUES ("1","name","value","/","www.example.net","www.example.net","2147483647")


In the settings of Firefox the cookies are the same like the real ones, but my inserted cookies are not sent. What's wrong?

DanRaisch
Moderator

User avatar
 
Posts: 120104
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted November 5th, 2013, 1:27 pm

Moving to Web Development.

jscher2000

User avatar
 
Posts: 10187
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted November 6th, 2013, 12:45 am

Why not use the the API for working with cookies?

https://developer.mozilla.org/en-US/doc ... ts/Cookies

BlackMatrix
 
Posts: 3
Joined: November 5th, 2013, 9:22 am

Post Posted November 6th, 2013, 2:02 am

I'm using .NET. The export ist just a small feature of my application and it shouldn't be difficult to add cookies just with SQLite and some commands. Is it really necessary to include any API? I think I forgot just a little thing for getting my cookies to be accepted by Firefox.

Frenzie

User avatar
 
Posts: 2134
Joined: May 5th, 2004, 10:40 am
Location: Belgium

Post Posted November 6th, 2013, 2:08 am

Does Firefox happen to be running while you do this?
Intelligent alien life does exist, otherwise they would have contacted us.

BlackMatrix
 
Posts: 3
Joined: November 5th, 2013, 9:22 am

Post Posted November 6th, 2013, 5:29 am

No, Firefox is not running.
I don't understand, because the cookies you can see in the privacy tab are the same like the real ones. If I logon a webpage with my login data I get another cookie with the same name, value, host and path under the same baseDomain like the real one. But Firefox doesn't have any notice of my cookies.

I will explain a little bit more. I have tried it with the "style_cookie" of the mozillaZine board.

Firefox doesn't notices that there is correct cookie already there.

You can see it here:

Image

Both have the same baseDomain, name, value, host and path and the expiry int value is bigger than the current date.

Code: Select all
            // Creating test cookie
            Cookie cookie = new Cookie();
            cookie.Name = "style_cookie";
            cookie.Value = "null";
            cookie.Path = "/";
            string host = "forums.mozillazine.org";

            // Create cookies.sqlite
            SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder();
            sb.DataSource="cookies.sqlite";

            using (SQLiteConnection connection = new SQLiteConnection(sb.ConnectionString))
            {
                // Open cookies.sqlite connection
                connection.Open();

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    // Create table moz_cookies
                    command.CommandText = "CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, appId, inBrowserElement))";
                    command.ExecuteNonQuery();

                    // Insert test cookie
                    command.CommandText = string.Format(
                        "INSERT INTO moz_cookies (baseDomain, name, value, path, host, expiry) VALUES (\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\")",
                        host,cookie.Name,cookie.Value,cookie.Path,host, 1483739327);
                    command.ExecuteNonQuery();
                }
            }

raxomi

User avatar
 
Posts: 8
Joined: August 2nd, 2014, 12:02 am

Post Posted December 6th, 2015, 2:33 pm

Remember that baseDomain must be only the domain name (ie example.com), and the host can be .example.com (will include all subdomains) or www.example.com (subdomain specific).

trolly
Moderator

User avatar
 
Posts: 39899
Joined: August 22nd, 2005, 7:25 am

Post Posted December 6th, 2015, 2:39 pm

No need to answer a two year old thread. Locking.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 1 guest