Asked 7 years ago
28 Mar 2017
Views 1084
jaydeep

jaydeep posted

cookie vs session in PHP

what is difference between cookie and session in PHP ?

Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

cookie is temporary data storage , and session is less temporary storage.

cookie is saved at user 's computer . in the form of temporary files.

session is saved at server

one can access the cookie because its stored at user 's Computer and session is not easy access because its saved to server . so session more secure than cookie. because session is not easy access.

in PHP
how to set cookie in PHP
 
set_cookie("cache","data", time()+3600);


how to set session in PHP

 
session_start();
$_SESSION['cache']='data';


session_start() used to start the session , its need to call session_start before set the any session variable.

Post Answer