+1 vote
147 views

Could you explain what is session and cookie and what is the difference between them?

asked Aug 22, 2015 in Computer Science - IT by T.PRATHIBA
edited May 12, 2016 by slow_learner | 147 views

1 Answer

+1 vote
Best answer

In general we have : meeting session,class session,gossip session :) etc.

Also Cookie : a small flat sweet cake.

But how come they be related to computing ?

In computing both sessions and cookies store information.

Main difference between both are, Session is stored in Server but at the same time cookies are stored in Client system.

Both may contain various information like userid,location,login times,username  and other values which will be useful.

You can also delete the cookies stored by any website using web-browser settings.

Edit 1 :

You open browser ,logs into enggforum , posts query and logs out.Actually you have had a session with enggforum.com,right ?

From the time when you log in till close the application enggforum must know details regarding your username and other details.How those details are stored ?

We have options like saving values in a client side as some text file or we can save in server.

Cookies are saved in client side as some text files and if you delete those files all related details are lost.

In order to make them store ,we have codings to be done ,you can see some examples here:

Syntax : 

setcookie(name, value, expire, path, domain, secure, httponly);

PHP cookies :

$cookie_name = "student";
$cookie_value = "Raj";
setcookie($cookie_name, $cookie_value, time() + (864 * 30), "/");

PHP sessions :

session_start();
$_SESSION["favcolor"] = "yellow";

As cookies are stored in client systems ,you can view them from Browser security settings as below screenshot shows :

 

 

answered Aug 23, 2015 by slow_learner
edited May 26, 2016 by slow_learner
@slow_learner,can u explain some more points with examples...
see the edited version and let know if further query....