Do i login using cookies or sessions in a login system?

半世苍凉 提交于 2020-01-15 05:11:06

问题


Do i login using cookies or sessions in a login system? I've seen examples using sessions and cookies so i am confused! Can someone please explain this?

What do most sites use? love to know!

Thanks in advance;-)


回答1:


Sessions - in most cases - use cookies to store their session id so its pretty much always a case that you are using both. Most sites will use sessions as cookies are inherently insecure as data is stored at the client side where as session data is stored on a server. It is largely a matter of security and what data you intend to store but since its so easy to modfify cookie data then you should never really trust anything within cookies.




回答2:


Login with Sessions because they are safer than cookies in that user's don't have direct access to your cookies.

BUT, when you use sessions, you are also using cookies, so in fact you are using both...

ex:

//query to get username from database

$_SESSION['user_id']=___
$_SESSION['username']=____

DON'T store passwords or anything sensitive in sessions or cookies




回答3:


A session is your server or applications idea of a person. In default PHP, when you create a session, a cookie is sent to the browser for storage. Every time the browser makes a request, it will send the cookie along and the server will lookup the information it has associated with that cookie. Sessions are good for storing user settings or server information because the user only ever sees the session key.

With cookies you can set a preference independent of the user or session at your site. Like the style of the page or whether this is a shared browser. This information will be sent with requests from that browser, so can be accessible from server scripts. The bonus with cookies is that javascript can use their values for processing without backend support (for static pages), and that the user can change them themselves.

Good advice above should be followed: put nothing in cookies you wouldn't want anyone to see.

Not only can the user see them, anyone with access to the users computer or the network connection between you and the user can see them.




回答4:


It is a bit of a minimalistic answer but here goes: - If your login system has a "remember me" feature, it very likely uses cookies but not sessions - If not, it uses cookies and sessions (because sessions use cookies as per said in above posts) Hope it helps



来源:https://stackoverflow.com/questions/3188182/do-i-login-using-cookies-or-sessions-in-a-login-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!