There are three main ways, we can get data from our users.
- By typing a url or click a link which will be a GET request.
- By submit a form which will be a POST request.
- Pulling values out of their browser COOKIE that send with every request they make.
and there is one more method to get data which is -
- SESSION
sessions are related to cookies.
A session is a file that stored on the web-server file system
not on the browser side.
So, when we want save some information, the process is instead of sending a cookie to the user, we send them as a reference to that session file.
So on every request they make to the web server after that they send the reference and were able to lookup that session file and pull all the data out of it.
So the most important difference with sessions that they stored in server-side not client-side.
All we send to the client is a reference to help us find that file.
Using sessions has some benefits and drawbacks -
PROS -
- More storage than cookie.
cookie is limited to 4000 characters maximum.
for session, it is limited to only by the file storage size
that you have on a web server i.e; how big is the hard-disk, that's the limit.
- Smaller request sizes because session uses reference.
- Conceals data values.
- More secure, less hackable.
CONS -
You won't see much difference on camparing to cookies, but it is.
- Expires when browser is closed.
Cookie can live 6 months or more.
- Session files accumulate.