+ 1

Session or cookie?

Well I have been working in a little project using PHP just to try the course stuff in there. It's only an insert, delete and update service. A few days ago I put a log in on my project just because I want to have a record of who insert or who delete etc. So I use a $_Session to store the User name so my code call the session variable to know the user's name. Today I was reading about how the cookies work and I'm wondering if my idea of storing the user name in a session was a good Idea. What do you think? What are the advantages and disadvantages of using one instead of the other? Thanks for your comments!

3rd Feb 2017, 4:03 PM
EarthKongol
EarthKongol - avatar
4 Réponses
+ 8
The discussion of cookies is very helpful
3rd Feb 2017, 8:48 PM
‎‏‎‏‎Joe
‎‏‎‏‎Joe - avatar
+ 5
the difference r: 1. còokie are returned stored in the user's browser wheras session data is stored on ur web server . 2.cookie Store data locally in the user's browser, while session store data on web server. 3.the life span of a cookie can b set to almost any duration of ur choosing but PHP session have a predetermined short life .the exact life span depend on how ur web host has configured PHP on ur web server. 4.depending on the web server is configured; session data is often stored in a public temporary directory on the server .as such it is possible other users on the server may be able to peek at data u store there. now u decide want u want with code☺
4th Feb 2017, 2:24 AM
kudhail
kudhail - avatar
+ 3
Use both. The cookie can persist between sessions, it's their raison d'etre.
3rd Feb 2017, 7:49 PM
Leon
Leon - avatar
+ 1
man cookies can not be store in data base you simply cant login with cookie method session is used to authorize the user and cookie is use to just read the name of your or store fir limited time
8th Mar 2017, 12:10 PM
Siddhant Rawate
Siddhant Rawate - avatar