Cookies vs sessions

0 votes
A few months ago, I first used PHP. I researched cookies, sessions, and their distinctions in order to build a login system for my website (cookies are saved in the user's browser; sessions are stored on the server). I favored cookies back then (because who doesn't like cookies? he just said: "Who cares? I can't get a reasonable deal to keep it on my server "I, therefore, decided to use cookies for my bachelor's thesis project. However, after finishing the bulk of my software, I learned that sessions are more suitable in this specific scenario for keeping the user's ID. So I began to consider what I would respond if the jury asked me why I had chosen to utilize cookies rather than sessions. Just for that reason (that I do not need to store internal information about the user). Is it sufficient as an excuse? or is there more to it?
Could you kindly explain the benefits and drawbacks of utilizing cookies to store the user's ID?
Aug 8, 2022 in PHP by Kithuzzz
• 38,000 points
626 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
The idea is to save persistent data for a web visitor between page loads. It is immediately stored on the client through cookies. Cookies are used by sessions as a kind of key to connect with the information kept on the server side.

Sessions are recommended because you have control over when the data expires and becomes invalid and because the client is not shown the actual values. If everything depended on cookies, a user (or hacker) may change their cookie information and then make requests to your website.

Edit: Aside from convenience, I don't see any benefits to using cookies. Consider it in this manner Do they have any justification for knowing their ID#? Normally, I would respond that the user does not require this information. Information should only be disclosed to those who need to know it. How will your application react if the user modifies his cookie to have a different ID? Security is at danger. Before sessions were popular, I essentially had my own method. I kept my permanent data in the database along with a special cookie value that I had put on the client.
answered Aug 8, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In PHP

0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,964 views
0 votes
1 answer

How to delete all cookies of my website in php?

Hello @kartik, This will unset all of the ...READ MORE

answered Oct 27, 2020 in PHP by Niroj
• 82,840 points
9,524 views
0 votes
0 answers

php var_dump() vs print_r()

What is the difference between var_dump() and print_r() in terms of ...READ MORE

May 28, 2022 in PHP by Kichu
• 19,040 points
606 views
0 votes
0 answers

PHP | define() vs. const

In PHP, there are two ways to ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
1,044 views
0 votes
0 answers

PHP "php://input" vs $_POST

I want to know what is the ...READ MORE

Jun 9, 2022 in PHP by Kichu
• 19,040 points
734 views
0 votes
0 answers

Using sessions & session variables in a PHP Login Script

I have created a login and register ...READ MORE

Jun 17, 2022 in PHP by narikkadan
• 63,600 points
729 views
0 votes
0 answers

What is the difference between Sessions and Cookies in PHP?

What is the distinction between Sessions and Cookies ...READ MORE

Jun 13, 2022 in PHP by narikkadan
• 63,600 points
477 views
0 votes
1 answer

"Cannot send session cache limiter - headers already sent"

The line "Headers already sent" means that ...READ MORE

answered Feb 18, 2022 in Others by Aditya
• 7,680 points
7,413 views
0 votes
0 answers

PHP Unset Session Variable

I am working on creating a product ...READ MORE

Jun 9, 2022 in PHP by Kichu
• 19,040 points
1,145 views
0 votes
0 answers

Why is PHP session_destroy() not working?

Why is session_destroy() not working? Is there any other way ...READ MORE

Jun 12, 2022 in PHP by narikkadan
• 63,600 points
1,523 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP