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

session or cookies ? who's better ?

session or cookies ? who's better ?

2 Answers

Chris Shaw
Chris Shaw
26,676 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.