Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Jin He
Jin He
8,123 Points

About the usage of cookies and session

Hey guys, I'm feeling confused about the usage of cookies and sessions, what kind of data should cookie store, what kind of data should session store, when should I use cookies to store data, when should I use session to store data ????

1 Answer

Logan R
Logan R
22,989 Points

I personally use session for user data, like user ids and usernames because sessions are more secure. Cookies on the other hand can be easily changed so it's better to use it for things like marking yes, the user has read this page, etc.

I am sure that's super vague, so check out this article: http://php.about.com/od/learnphp/qt/session_cookie.htm

A cookie can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit.

Sessions are not reliant on the user allowing a cookie. They work instead like a token allowing access and passing information while the user has their browser open.