Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

session or cookies ? who's better ?

session or cookies ? who's better ?

2 Answers

Chris Shaw
Chris Shaw
26,662 Points

Hi Hamza,

It really depends on what you need to use them for, generally now day's it's much better to use a session as it's more secure and can't be used in the same way a cookie can which is that you can access cookies both server and client side whereas a session can only be used by the server and stay alive given the browser is sending a correct session id which the server generates.

It simply depends on what you need to do.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

As with most things the answer is... it depends. What is the goal you are trying to accomplish? While similar, cookies and sessions are not exactly the same thing. They can be used for similar purposes, but tend to offer a different set of results and user experiences.