When should we use session and cookies in PHP? Please specify separately their uses,pros and cons.
When should we use session and cookies in PHP? Please specify separately their uses,pros
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, explaining it “separately” will be difficult since cookies are mostly used to store a session identifier on the clients machine. This is done by PHP automatically as soon as you start session (can be configured differently).
The session is then used to identify and recognize the user and to pass information from one request to the next that the user must not be allowed to modify (session data is stored on the server).
Cookies can also be used to store data on the clients machine that is not security related and that can be used to remember a certain state on the page for the user for example.
Just remember: Cookies can be easily manipulated. Use Session for everything that is security related.