I know there are several articles on cookies as what are they? and how can they be created? but i always wanted to know more about them. My questions were where they are stored? how to track their expiry? If they contain user centric information then Can they be encrypted?
Lets explore each of my question then we will go more into coding part of cookies. I remember the first definition of cookie that i learned
“Cookie is a text file which is stored at the user’s hard disk and contains user’s session information”
This definition is very much synonymous to Google definition:
“A small sweet cake, typically round, flat, and crisp.”
Good.Right? Our Cookie is a small file like small cake and provided sweet feeling by streamlining our session information.
But when i really started working on cookies, I had my share of queries and resolutions like I came to know that as ‘http’ is a stateless protocol so we always have to attach our session information.
What is this session information and why it is required every time?
Well, the best answer is user expectations, we always want our web to be extra smart.Don’t we?
if i say, you don’t have to sign in to your Gmail account on each request or you don’t have to add the items on your shopping basket every time or you just want your website to tell you,when you visited the site last time.
This is the smart decisions we expect from our website but as HTTP protocol is stateless and can’t retain our information then what it did, it provided a Cookie mechanism to store the information at user’s side and send it to server on each request where it gets modified as per the request and sent back to the user to store it again.
Here, I’ll sweetify the definition a bit:
“Cookie is a piece of client’s information kept at client’s side in the form of a text file and , on each request and response, this information travels between the server and client”
No files travels between server and client, only information travels in between server and client. At client side, information is read by the ‘HTTP’ request from this text file and while the response is received, this file is written with the updated information again.
So where this file is located, It depends on the browser so let’s believe what we see now.
Run this: %AppData%\Mozilla\Firefox\Profiles\%FirefoxProfile%\cookies.sqlite To read the data you need to connect to that database and query the DB
In Internet Explorer
Run this : %AppData%\Microsoft\Windows\Cookies
Run this: %AppData%\\Google\Chrome\User Data\Default\Cookies
Now, we have seen our cookies and found that they really exists. We have a lot of information to cover so we will try to find answers for more of our queries in next article of this series. Cookies Part 2