6

Lamp was installed on my local pc whose os is debian8 .
That is to say the client and server were all installed on my local pc.
The following code was saved as setcookie.php on my local pc.

<?php
setcookie("user", "Alex Porter", time()+36000);
?>

<html>
<body>

</body>
</html>

Now php setcookie.php was executed on my local pc. The following codes were all executed on my local pc.

find /  -name   "cookies.sqlite"
/home/debian8/.mozilla/firefox/joww2h34.default/cookies.sqlite

sqlite3  /home/debian8/.mozilla/firefox/joww2h34.default/cookies.sqlite
sqlite> .tables
moz_cookies
sqlite>     PRAGMA table_info([moz_cookies]);
0|id|INTEGER|0||1
1|baseDomain|TEXT|0||0
2|appId|INTEGER|0|0|0
3|inBrowserElement|INTEGER|0|0|0
4|name|TEXT|0||0
5|value|TEXT|0||0
6|host|TEXT|0||0
7|path|TEXT|0||0
8|expiry|INTEGER|0||0
9|lastAccessed|INTEGER|0||0
10|creationTime|INTEGER|0||0
11|isSecure|INTEGER|0||0
12|isHttpOnly|INTEGER|0||0

sqlite>     select *  from moz_cookies where name="Alex Porter";
sqlite> select *  from moz_cookies where name="user";

Why there is no info selected for both of them ?
Do my cookie be set or not in my firefox? If it is set on my firefrox,why can't be selected in the sqlite statement?
In my opinion , the sql command select * from moz_cookies where name="Alex Porter"; will get such something as

name  user  value Alex Porter  expires 1515832198

Nothing display. Do as Aadil P. say the file was saved as setcookie.php in /var/www/html/tmp/setcookie.php. Executed 127.0.0.1/tmp/setcookie.php in firefox.
Open the Cookies with firebug.

enter image description here

The right result displayed here.
Two problem remains:
1.How many fields for the cookie?

PRAGMA table_info([moz_cookies]);
0|id|INTEGER|0||1
1|baseDomain|TEXT|0||0
2|appId|INTEGER|0|0|0
3|inBrowserElement|INTEGER|0|0|0
4|name|TEXT|0||0
5|value|TEXT|0||0
6|host|TEXT|0||0
7|path|TEXT|0||0
8|expiry|INTEGER|0||0
9|lastAccessed|INTEGER|0||0
10|creationTime|INTEGER|0||0
11|isSecure|INTEGER|0||0
12|isHttpOnly|INTEGER|0||0

There are only name,value,domain,raw size,path,expires,httponly,security in firebug cookies widow.
Why they are not the same?How many cookie elements on the related international standard?

2.How to write the proper sql command?

select *  from moz_cookies where name="user";
select *  from moz_cookies where Name="user";

Both of them get nothing.

showkey
  • 482
  • 42
  • 140
  • 295
  • Try `SELECT name, value FROM moz_cookies WHERE baseDomain = 'stackoverflow.com';`. How did you try to actually set the cookie? – CL. Jan 14 '16 at 08:41
  • The file was saved as 'setcookie.php' on my local pc,and executed 'php setcookie.php'. – showkey Jan 14 '16 at 08:45
  • you want to set database values in cookie and want to access in your website ? – Monty Jan 20 '16 at 06:04
  • https://en.wikipedia.org/wiki/HTTP_cookie#cite_note-Peng.2C_Weihong_2000-19 – showkey Jan 23 '16 at 02:02
  • only six elements(or say fields discussed :Domain and Path,Expires and Max-Age,Secure and HttpOnly,but 12 elements discussed in cookie.sqlite : baseDomain,appId,inBrowserElement,name,value,host,path,expiry,lastAccessed,creat‌​ionTime,isSecure,isHttpOnly. How many cookie elements on the related international standard? – showkey Jan 23 '16 at 02:02

2 Answers2

6

You are using php setcookie.php to execute the php file via cli (as per your comment). Cookie or HTTP Cookie is stored in user's web browser.... [As per Wikipedia - https://en.wikipedia.org/wiki/HTTP_cookie]

You need to to open/execute this php file in a browser as mentioned by CL.

Since you have LAMP installed, move the script (php file) to a LAMP folder and open the page in browser by calling the file, your url address bar should look like http://localhost/setcookine.php(or http://127.0.0.1//setcookie.php) or something similar depending upon where the file is located.

Edit: Why don't you try listing all cookies for the table by simply

SELECT id,name FROM moz_cookies;

to see if there are any cookies at all? If you see the cookie in the list, then your query has an error, else you might be in the wrong sqlite file altogether.

Try the following as well

select * from moz_cookies where name like "%name%";
Aadil P.
  • 150
  • 14
  • The attributes of a cookie (fields for cookie) are mentioned on the Wikipedia page. Can you give us a better idea of what actually you are trying to achieve? – Aadil P. Jan 14 '16 at 09:20
  • The 2rd problem solved, after rebooting my pc,mayebe it is a problem of cache. – showkey Jan 14 '16 at 10:56
  • The first remains,why the cookie fields in cookies.sqlite of firefox is not the same as in firebug cookie window? – showkey Jan 14 '16 at 10:58
  • In the url [https://en.wikipedia.org/wiki/HTTP_cookie#cite_note-Peng.2C_Weihong_2000-19] , only six elements(or say fields discussed :Domain and Path,Expires and Max-Age,Secure and HttpOnly,but 12 elements discussed in cookie.sqlite : baseDomain,appId,inBrowserElement,name,value,host,path,expiry,lastAccessed,creationTime,isSecure,isHttpOnly. How many cookie elements on the related international standard? – showkey Jan 14 '16 at 11:05
4

To set a cookie in Firefox, you have to view the web page in Firefox.

You probably want to run a PHP server on local machine.

Community
  • 1
  • 1
CL.
  • 173,858
  • 17
  • 217
  • 259